作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我的需求
<PreferenceScreen>
<PreferenceCategory
style="@style/settings_category_text"
android:title="Section 1 Heading" >
<Preference
android:key="section1_key1"
android:title="Pref 1">
</Preference>
</PreferenceCategory>
<PreferenceCategory
style="@style/settings_category_text"
android:key="extra_settings_category"
android:title="Section 2 Heading" >
<PreferenceScreen
android:key="sub_screen"
android:title="Sub screen of settings"
android:summary="">
<intent
android:targetPackage="com.my.test"
android:targetClass="com.my.test.SubScreenPreferenceActivity" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen>
<PreferenceCategory
style="@style/settings_category_text"
android:title="Additional Settings" >
<ListPreference
android:key="list_pref1"
android:title="List Pref 1"
android:defaultValue="1"
android:entries="@array/list_pref1_titles"
android:entryValues="@array/list_pref1_values"
android:summary="%s"
/>
<ListPreference
android:key="list_pref2"
android:title="List Pref 2"
android:defaultValue="1"
android:entries="@array/list_pref2_titles"
android:entryValues="@array/list_pref2_values"
android:summary="%s"
/>
</PreferenceCategory>
</PreferenceScreen>
<string-array name="list_pref1_titles">
<item>Apples</item>
<item>Pears</item>
<item>Bananas</item>
</string-array>
<string-array name="list_pref1_values">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="list_pref2_titles">
<item>Cream</item>
<item>Ice Cream</item>
<item>Custard</item>
</string-array>
<string-array name="list_pref2_values">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
Section 1 Heading
-----------------
Pref 1
Section 2 Heading
-----------------
Sub screen of settings
Additional Settings
-------------------
List Pref 1
Apples
List Pref 2
Cream
Section 1 Heading
----------------
Pref 1
Section 2 Heading
------------------
Sub screen of settings
Apples, Cream
Account & Settings | Sync Settings
AppIcon myAccount
appName
Section 2 Heading
-----------------
Sub screen of settings
Apples, Cream
DATA & SYNCHRONIZATION
----------------------
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="myAccount"
android:icon="@drawable/launcher"
android:label="@string/app_name"
android:smallIcon="@drawable/launcher"
android:accountPreferences="@xml/account_preferences"/>
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceCategory
style="@style/settings_category_text"
android:key="extra_settings_category"
android:title="Section 2 Heading" />
<PreferenceScreen
android:key="sub_screen"
android:title="Sub screen of settings"
android:summary="">
<intent
android:targetPackage="com.my.test"
android:targetClass="com.my.test.SubScreenPreferenceActivity" />
</PreferenceScreen>
</PreferenceScreen>
最佳答案
我自己解决了这个问题。事实证明它并不太复杂。
在第一个首选项屏幕的 Activity 的“onResume”中,我只是调用一个实用程序方法来生成首选项的摘要字符串,其摘要包含第二个屏幕中所有选定值的值。此实用程序方法查询存储的首选项以获取首选项值,然后组成一个合适的字符串。由于此实用程序方法检查存储的首选项的值,因此当您第一次进入 Activity 以及从子屏幕返回 Activity 时,摘要将是准确的。
例如
在“com.my.test.MainPreferenceActivity”“onResume”方法中我有以下
// update the preference's summary to a string containing the values selected in the sub-screen
Preference syncPref = findPreference(SUB_SCREN_OF_SETTINGS);
syncPref.setSummary(getSubScreenSummary(....));
public String getSubScreenSummary(){
// get the value of list_pref_1
// get the value of list_pref_2
String s = ...... // build up the string based on values of list_pref_1/list_pref_2
return s;
}
关于安卓 : Set a preference's summary in a main preference screen to the values selected in a sub preference screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18123823/
我是一名优秀的程序员,十分优秀!