目前,对于我的2.x首选项屏幕,在每个PreferenceActivity中,我添加了行setContentView(R.layout.activity_preferences);
以在我的活动中设置自定义布局。
activity_preferences.xml布局文件如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout style="@style/TitleBar">
<ImageButton style="@style/TitleBarAction"
android:src="@drawable/ic_title_home"
android:onClick="onHomeClick" />
<ImageView style="@style/TitleBarSeparator" />
<eu.vranckaert.worktime.utils.view.CustomTextView
style="@style/TitleBarText" android:text="@string/lbl_preferences_title"/>
</LinearLayout>
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"/>
</LinearLayout>
对于我的3.x及以上应用程序,我正在根据此处的示例构建首选项:http://developer.android.com/reference/android/preference/PreferenceActivity.html。
为了将相同的布局应用于我的3.x应用,我尝试在3.x PreferenceActivity中添加setContentView(..)
。
手机上的结果:这在第一个活动上工作正常,然后在加载片段时(其中包含真实的偏好)我的样式不适用
平板电脑上的结果:崩溃:
ERROR/AndroidRuntime(2208): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{eu.vranckaert.worktime/eu.vranckaert.worktime.activities.preferences.PreferencesICSActivity}: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment TimeRegistrationsPreferencesFragment{4101ed38 #0 id=0x10202d4}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment TimeRegistrationsPreferencesFragment{4101ed38 #0 id=0x10202d4}
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:822)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
at android.app.BackStackRecord.run(BackStackRecord.java:622)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
at android.app.Activity.performStart(Activity.java:4474)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
... 11 more
当我尝试使用getActivity().setContentView(R.layout.activity_preferences);
在我的片段上应用布局文件时,结果为:
对于电话:活动仍然显示正常,当进入一个类别它崩溃:
ERROR/AndroidRuntime(1320): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{eu.vranckaert.worktime/eu.vranckaert.worktime.activities.preferences.PreferencesICSActivity}: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment DateTimePreferencesFragment{412a0d78 #0 id=0x10202d4}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment TimeRegistrationsPreferencesFragment{412a0d78 #0 id=0x10202d4}
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:822)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
at android.app.BackStackRecord.run(BackStackRecord.java:622)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
at android.app.Activity.performStart(Activity.java:4474)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
... 11 more
平板电脑的:与以前一样崩溃......
我应该如何将此布局文件应用于我的片段活动...?或者我应该创建一个新的布局文件?