开发者

setcurrenttab from preference

开发者 https://www.devze.com 2023-01-05 13:17 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消