Starting a PreferenceActivity from a TabActivity
I have a TabActivity
which starts when the application is launched. It contains 3 tabs.
I have added a Settings option in the OptionMenu which when clicked starts a custom PreferenceActivity
. it is a simple activity which does
addPreferencesFromResource(R.xml.preferences);
in its onCreate
method. However, when the user clicks on the Settings
option, I receiv开发者_如何学Pythone this warning and nothing is shown at all :
07-07 13:07:56.397: WARN/InputManagerService(110): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4075fa28
What exactly is the problem with this? Is there any special way to handle Calling Activities inside TabActivity
. How to fix this?
Thanks in advance.
Use the intent framework that indicates which custom PreferenceActivity
to start. Something like below, I think.
getTabHost().addTabSpec().setContent(yourIntentHere);
Here's what I do:
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
Then, for each tab:
intent = new Intent().setClass(this, YOURCLASS.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("JUSTSOMENAME")
.setContent(intent);
tabHost.addTab(spec);
Instead of the using the xml
, I did this programmatically inside each of the activities and it worked fine.
精彩评论