Android PreferenceScreen-我可以在不将首选项保存到SharedPreferences的情况下使用它吗? [英] Android PreferenceScreen - Can I use it without saving preferences to SharedPreferences?
问题描述
我正在尝试使用Android PreferenceScreen
作为布局用户设置的便捷方法,但是我不想将首选项保存为设备共享首选项.这可能吗,还是我应该使用其他机制,例如 ListView
?
I'm trying to use the Android PreferenceScreen
as a convenient way to layout my user settings, but I don't want to save the preferences to the device shared preferences. Is this possible, or should I be using a different mechanism such as ListView
?
使用 PreferenceScreen
类型似乎真的很方便,因为我需要不同的小部件(即开关,编辑文本).但是我已经遇到了持久性问题,即.我输入的所有内容都会保留,即使我不想在整个会话中都保留.
It seems really convenient to use the PreferenceScreen
type because I require different widgets (ie. switches, edit text). But I'm already running into problems with persistence, ie. anything I enter is persisted even across sessions when I don't want it to be.
settings.xml:
settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Preference
android:key="settings_type"
android:title="@string/label_type" />
<EditTextPreference
android:key="settings_edit_name"
android:title="@string/label_name"
android:dialogTitle="Enter a name"
android:singleLine="true" />
<SwitchPreference
android:key="settings_edit_state"
android:title="@string/label_state"
android:summary="Enable or disable the state" />
</PreferenceScreen>
推荐答案
您可以只使用线性布局,然后将所需组件的非首选版本放置在其中.
You can just use a linear layout and place the non-preference versions of the components you want in it.
这篇关于Android PreferenceScreen-我可以在不将首选项保存到SharedPreferences的情况下使用它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!