アンドロイドでtablayoutの一つのタブで..アンドロイドのタブレイアウトの1つのタブでonWindowFocusChanged(boolean)メソッドをtrue(または呼び出し)にする方法は?真(またはコール)に(ブール値)onWindowFocusChangedメソッドを作成する方法
説明:tablayoutで
はonWindowFocusChangedは、()(真)デフォルトのアクティビティに自動的に呼び出され、しかし、次のタブ(他のアクティビティを呼び出す)をクリック/タッチすると、 はonWindowFocusChanged()を呼び出せません!!!!!! 2番目のタブでonWindowFocusChanged()を呼び出す方法は?
ソースコード:
public class TabTestActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, TabOne.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("TabOne").setIndicator("TabOne",
res.getDrawable(R.drawable.ic_tab_One))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, TabTwo.class);
spec = tabHost.newTabSpec("TabTwo").setIndicator("TabTwo",
res.getDrawable(R.drawable.ic_tab_az))
.setContent(intent);
tabHost.addTab(spec);
//tabHost.setCurrentTab(2);
}
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
Toast.makeText(this, ""+hasFocus , Toast.LENGTH_LONG).show();
super.onWindowFocusChanged(hasFocus);
}
}
-----------------------------------------------------------------------------------------------------
public class TabOne extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Coll tab");
setContentView(textview);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
Toast.makeText(this, "On window One"+hasFocus , Toast.LENGTH_LONG).show();
super.onWindowFocusChanged(hasFocus);
}
}
--------------------------------------------------------------------------
public class TabTwo extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Coll tab");
setContentView(textview);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
Toast.makeText(this, "On window TabTwo"+hasFocus , Toast.LENGTH_LONG).show();
super.onWindowFocusChanged(hasFocus);
}
}
TabTwoの(2ndTab)はTabTwo活動がソリューションを与えてください実行している間は呼び出されませんonWindowFocusChanged。 私はtabHost.setFocusable(true)を提供しようとしました。私は働いていません!!!
はTabOneのonWindowFocusedと呼ばれていますか? –
@ sadeshKumar:はい、TabOnes onWindowFocusedを呼び出します。 –