Android tabactivity problem
I'm having some difficulties getting the TabActivity to work. Here's the implementation of the class:
public class Profile extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TabHost tabHost = getTabHost();
if (tabHost.isEnabled()) {
Log.e("profile", "enabled");
}
tabHost.addTab(tabHost.newTabSpec(getString(R.string.friendReqs))
.setIndicator("requests")
.setContent(new Intent(this, FriendRequests.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.addTab(tabHost.newTabSpec(getString(R.string.friends))
.setIndicator("photo list")
.setContent(new Intent(th开发者_如何学运维is, Settings.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
Log.e("profile", "add tabs");
tabHost.invalidate();
}
}
The problem is that I call this class from my main activity (which is a MapActivity if it matters) and when I do the TabActivity doesn't show. It registers the click on the option menu and it even starts the intent but the screen doesn't change..it just stays on the main activity and i see in the logs that the main activity gets resumed. I call it like this:
Intent p = new Intent(this,Profile.class);
p.putExtra(DBAdapter.KEY_USERID,userid);
startActivity(p);
Like I said...there are no errors (the classes called from the tabs exist of course), just no actions. I put some log commands into the onCreate function in the tabactivity (as you see) and they all get written into the log...I have no idea what I'm doing wrong here. Any help?
After some tries...
I set the first tab to a view instead of an intent and it showed the tabs...i could also select the 2nd tab.
Got it. The problem was the Activity being called in the 1st tab. It closed if there was no data passed to it (bundle). Thanks again for the help.
Remove
tabHost.invalidate();
Also you can drop
Intent.FLAG_ACTIVITY_CLEAR_TOP
I don't see any purpose of this, as you need to see the activity anyway when you click on tabs.
I don't see setContentView() in your Activity, which you need.
精彩评论