所以我有這種偏好活動,似乎無法弄清楚如何使這項工作,如果它可以做到。我的應用程序使用Sherlock Actionbar,View-pager和Fragment Tabs。我的所有標籤都不是最後一個,這是我的PreferenceActivity。使用Sherlock ActionBar,片段Tab的,ViewPager,PreferenceActivity
public class Prefs extends SherlockPreferenceActivity implements
OnSharedPreferenceChangeListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
Preference customPref = (Preference) findPreference("clearcache");
customPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(getBaseContext(), "Cache Cleared",
Toast.LENGTH_LONG).show();
Webview.web.clearCache(true);
return false;
}
});
Preference customerPref1 = (Preference) findPreference("intent1");
customerPref1
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent myIntent = new Intent(Prefs.this, Intent1.class);
Prefs.this.startActivity(myIntent);
return true;
}
});
這就是我的偏好活動設置。選擇此選項卡時,主要問題如下。
logcat的
03-07 10:55:09.553: E/AndroidRuntime(3968): FATAL EXCEPTION: main
03-07 10:55:09.553: E/AndroidRuntime(3968): java.lang.ClassCastException: com.application.example.EditPreferences cannot be cast to android.support.v4.app.Fragment
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
03-07 10:55:09.553: E/AndroidRuntime(3968): at com.application.example.ABSTabsViewPagerActivity$TabsAdapter.getItem(ABSTabsViewPagerActivity.java:106)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:97)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:800)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.support.v4.view.ViewPager.populate(ViewPager.java:991)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.support.v4.view.ViewPager.populate(ViewPager.java:880)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1374)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.View.measure(View.java:15518)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.View.measure(View.java:15518)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.View.measure(View.java:15518)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-07 10:55:09.553: E/AndroidRuntime(3968): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.View.measure(View.java:15518)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.Choreographer.doFrame(Choreographer.java:532)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.os.Handler.handleCallback(Handler.java:725)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.os.Looper.loop(Looper.java:137)
03-07 10:55:09.553: E/AndroidRuntime(3968): at android.app.ActivityThread.main(ActivityThread.java:5204)
03-07 10:55:09.553: E/AndroidRuntime(3968): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 10:55:09.553: E/AndroidRuntime(3968): at java.lang.reflect.Method.invoke(Method.java:511)
03-07 10:55:09.553: E/AndroidRuntime(3968): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
03-07 10:55:09.553: E/AndroidRuntime(3968): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
03-07 10:55:09.553: E/AndroidRuntime(3968): at dalvik.system.NativeStart.main(Native Method)
任何想法的,例如,其他的建議,是能夠做一個設置頁,即使其他的例子,我的大部分設置都只是意圖的其他活動。
我不認爲這是可能實現PreferenceActivity成ViewPager – Nickolaus 2013-03-07 18:41:38
嘗試從SherlockFragment延伸的活動不會在ViewPager – Marcin 2013-03-07 18:46:19
@Marcin工作變爲SherlockFragment後,我所有的「findPreference」是不確定的。 – 2013-03-07 18:50:18