[英]Preference Activity Vs PreferenceFragment?
In preference Activity we can use these two methods SetContentView(R.layout.main)
and addXmlFromResources(R.xml.Preferences)
for customizing the preference screen. 在首选Activity中,我们可以使用这两个方法
SetContentView(R.layout.main)
和addXmlFromResources(R.xml.Preferences)
来自定义首选项屏幕。 For example see this Adding a button on Prefernce Screen 例如,请在Prefernce Screen上看到这个添加按钮
Is this possible in PreferenceFragment? 这在PreferenceFragment中是否可行?
In PreferenceFragment, I have added addPreferencesFromResource(R.xml.PreferenceScreen);
在PreferenceFragment中,我添加了
addPreferencesFromResource(R.xml.PreferenceScreen);
in onCreate method. 在onCreate方法中。 When I use onCreateView it's getting force closes.
当我使用onCreateView时,它会被强制关闭。 I have tried Layout Inflator also.
我也试过布局充气机。 It's not working.
它不起作用。
So is this possible only on preference Activity? 那么这只能在首选项Activity上实现吗? not Preference Fragment?
不是偏好片段?
PS- I am using support V 13 Library. PS-我正在使用支持V 13库。 So I have created Preference Fragment in Fragment Pager Adapter.
所以我在Fragment Pager Adapter中创建了Preference Fragment。 Please don't suggest to me to create Preference Activity for preference Fragment
请不要建议我为首选片段创建首选项活动
You can use 您可以使用
addPreferencesFromResource(int res);
in both PreferenceFragment
and PreferenceActivity
, inside the onCreate()
method. 在这两个
PreferenceFragment
和PreferenceActivity
,内侧onCreate()
方法。 Bear in mind that PreferenceFragment
should be used in post Honeycomb Android Versions as a replacement for PreferenceActivity
. 请记住,
PreferenceFragment
应该在后Honeycomb Android版本中用作PreferenceActivity
的替代品。
If you want a custom-layout for your PreferenceActivity
, you can call setContentView()
in the onBuildHeaders()
method, but not in the onCreate()
. 如果需要
PreferenceActivity
的自定义布局,可以在onBuildHeaders()
方法中调用setContentView()
,但不能在onCreate()
调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.