現在ActivityにFragmentTabを4つ作成しており、別のSubActivityからボタン押したら3つ目のFragmentTabに移動したいのですがどうしたら良いでしょうか?
MainActivity
MainAcitvity
1 TabHost.TabSpec tabSpec1, tabSpec2, tabSpec3, tabSpec4; 2 3 // TabSpec を生成する 4 tabSpec1 = tabHost.newTabSpec("tab1"); 5 6 tabSpec1.setIndicator("tab1"); 7 8 tabHost.addTab(tabSpec1, tab1Fragment.class, null); 9 10 11 // TabSpec を生成する 12 tabSpec2 = tabHost.newTabSpec("tab2"); 13 tabSpec2.setIndicator("tab2"); 14 15 16 // TabHost に追加 17 tabHost.addTab(tabSpec2, tab2Fragment.class, null); 18 19 20 // TabSpec を生成する 21 tabSpec3 = tabHost.newTabSpec("tab3"); 22 tabSpec3.setIndicator("tab3"); 23 Bundle bundle3 = new Bundle(); 24 bundle3.putString("name", "Tab3"); 25 // TabHost に追加 26 tabHost.addTab(tabSpec3, tab3Fragment.class, bundle3); 27 28 // TabSpec を生成する 29 tabSpec4 = tabHost.newTabSpec("tab4"); 30 tabSpec4.setIndicator("マイtab4"); 31 32 // TabHost に追加 33 tabHost.addTab(tabSpec4, tab4Fragment.class, null); 34
SubActivityの処理が完了したら
new Thread(new Runnable() { @Override public void run() { ーー中略ーーー handler.post(new Runnable() {// @Override// public void run() {// AlertDialog.Builder adb = new AlertDialog.Builder(SubActivity.this); adb.setMessage("リストを確認してください。"); adb.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.tabHost.setCurrentTab(2); } }); }// });// }
としているのですが
MainActivity.tabHost.setCurrentTab(2);の行で
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
エラーで落ちます。
教えて頂きたいです。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。