The default tab that is displayed in my app is tab 0. I would like when Preference uso is clicked, to change the currentTab to 1, as well as the next time the app opens, tab 1 is displayed instead of tab 0.
This is the Preferences.java contents:
package com.fbisoft.uowt;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.TabHost;
import android.widget.Toast;
public class Preferences extends PreferenceActivity {
/** Called when the activity is first created. */
开发者_如何学Python@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
getPreferenceManager().findPreference("uso").setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
TabHost.setCurrentTab(1);
return true;
}
});
}
}
The TabHost.setCurrentTab(1);
gives me an error:
Cannot make a static reference to the non-static method setCurrentTab(int)
from the type TabHost
You need to have your activity that has the TabHost
watch for preference changes, then change your tab there. You cannot tell the TabHost
class to change a tab.
精彩评论