gpt4 book ai didi

java - Android PreferenceList,选择后的子列表

转载 作者:行者123 更新时间:2023-12-01 05:28:11 25 4
gpt4 key购买 nike

我正在寻找一种方法,在用户在列表首选项中选择一个选项后,在首选项中显示第二个列表

例如:用户从列表中选择“发送短信至”选项,然后出现第二个列表,用户可以选择联系人。

目前,我正在尝试从我的首选项 Activity 中放置一个 onSharedPreferenceChanged 方法,并在选择后显示一个包含联系人的警报对话框,但我认为还有另一种方法...但我还没有找到它互联网...

有人知道这是怎么可能的吗?

谢谢

最佳答案

在您的 PreferenceActivity 中放置一个如下所示的方法,用于监听何时单击该特定键。

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {

//Make sure the item changed was the list_preference
if(key.equals("list_preference")) {
String value = sharedPreferences.getString(key, "Nothing");

if(value.equals("Send_sms")) {
//launch AlertDialog with list or launch new preference
}
}
}

关于java - Android PreferenceList,选择后的子列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9431484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com