I know there are a lot of questions about this subject but I can't get it working on my application. My problem is. I have an App with 4 Tabs. In 3 of them there is a webView
. Every time I change Tabs the whole fragment
just reloads. I want it to load it again. So when I lost my internet connection it will still show the page that was open.
This is my mainactivity:
public class MainActivity extends FragmentActivity {
private FragmentTabHost TabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//instellingen laden
final SharedPreferences settings = getSharedPreferences("Leerling", 0);
//lln laden
int lln = settings.getInt("lln", 0);
if(lln == 0) {
//alert maken
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Welkom");
alert.setMessage("Vul je LLN in:");
// EditText maken
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
alert.setView(input);
//ga knop
alert.setPositiveButton("Ga", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//String text = input.getEditableText().toString();
int lln = Integer.parseInt(input.getEditableText().toString());
SharedPreferences.Editor editor = settings.edit();
editor.putInt("lln", lln);
editor.commit();
}
});
//stop knop
alert.setNegativeButton("Stop", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
android.os.Process.killProcess(android.os.Process.myPid());
return;
}
});
alert.show();
}
TabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
TabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
//tab1 toevoegen
TabHost.addTab(TabHost.newTabSpec("tab1").setIndicator("Rooster"), Tab1.class, null);
//tab2 toevoegen
TabHost.addTab(TabHost.newTabSpec("tab2").setIndicator("Pers"), Tab2.class, null);
//tab3 toevoegen
TabHost.addTab(TabHost.newTabSpec("tab3").setIndicator("Wijzig"), Tab3.class, null);
//tab4 toevoegen
TabHost.addTab(TabHost.newTabSpec("tab4").setIndicator("Extra's"), Tab4.class, null);
}
And this is my Tab1:
public class Tab1 extends Fragment {
private Bundle webViewBundle;
private WebView webViewRooster;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View View = inflater.inflate(R.layout.activity_tab1, container, false);
SharedPreferences settings = getActivity().getSharedPreferences("Leerling", 0);
int lln = settings.getInt("lln", 0);
webViewRooster = (WebView) View.findViewById(R.id.webViewRooster);
webViewRooster.setWebViewClient(new WebViewClient());
if (webViewBundle == null) {
Toast.makeText(getActivity(), "geladen voor eerste x", Toast.LENGTH_SHORT).show();
webViewRooster.loadUrl("http://www.idylank.x90x.net/rooster.php?lln=" + lln);
}
else{
Toast.makeText(getActivity(), "tweede of meer x", Toast.LENGTH_SHORT).show();
//webViewRooster.restoreState(webViewBundle);
}
return View;
}
public void onPause() {
webViewBundle = new Bundle();
webViewRooster.saveState(webViewBundle);
super.onPause();
}
I tried a lot of things... Please help.