Hi Droids,
It's a beginner Droid developer question!!!
how to make the method onWindowFocusChanged(boolean hasFocus ) to
true in tabs of tablayout in android..
Exp:
In tablayout onWindowFocusChanged( boolean hasFocus ) called
automatically in default(first) activity (first tab button) , But
when we click/touch on to the next tab ( which call another activity)
not able to call the onWindowFocusChanged( boolean
hasFocus ) !!!!!! how to call onWindowFocusChanged() in second tab?
or any other way to make tabview and call the activities??
source code:
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)
{ //called when this tab clicked
// 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) { //Not
called when this tab clicked
// TODO Auto-generated method stub
Toast.makeText(this, "On window TabTwo"+hasFocus ,
Toast.LENGTH_LONG).show();
super.onWindowFocusChanged(hasFocus);
}
}
//--------------------------------------------------------------------------------------------------------------------------------
TabTwo's onWindowFocusChanged not called while touching on to the
second tab(TabTwo).. please give the solution.
I tried to provide tabHost.setFocusable(true); I doesn't worked!!!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en