是否有可能从一个适配器加载列表preference项目? [英] Is it possible to load ListPreference items from an adapter?

查看:165
本文介绍了是否有可能从一个适配器加载列表preference项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了​​创建为我的应用程序设置一个活动。我已经定义了一个 preferenceActivity 有一个很好的布局,包括目录preference 目标用户选择一个蓝牙设备。 我无法动态填充列表

I'm setting out to create a settings activity for my app. I've defined a PreferenceActivity with a nice layout including a ListPreference object for the user to select a bluetooth device. I'm having trouble dynamically populating the list.

我想填充目录preference 从一个阵列适配器值(我将创建并填充与相关蓝牙设备名称)。

I would like to populate ListPreference with values from an array adapter (which I'll create and populate with relevant bluetooth device names).

如果这是一个微调视图,我可以叫 setAdapter()。然而,随着目录preference 对象我无法弄清楚如何将一个适配器( findviewByID 荣获'牛逼投从视野中目录preference ,所以我甚至不能得到一个处理的对象)。

If this were a spinner View, I could just call setAdapter(). However with the ListPreference object I can't figure out how to attach an adapter (findviewByID won't cast from View To ListPreference, so I can't even get a handle to the object).

我要附加一个适配器,然后填充适配器值,这反过来会填充目录preference 与价值观。

I would like to attach an adapter and then populate the adapter with values, which in turn would populate the ListPreference with values.

推荐答案

目录preference 不带适配器的工作,这也适用于字符串。请参阅<一href="http://developer.android.com/reference/android/$p$pference/List$p$pference.html#setEntries%28java.lang.CharSequence%5b%5d%29"><$c$c>setEntries()和<一href="http://developer.android.com/reference/android/$p$pference/List$p$pference.html#setEntryValues%28java.lang.CharSequence%5b%5d%29"><$c$c>setEntryValues()

ListPreference doesn't work with adapters, it works with strings. See setEntries() and setEntryValues()

要得到你的目录preference ,叫<一href="http://developer.android.com/reference/android/$p$pference/$p$pferenceActivity.html#find$p$pference%28java.lang.CharSequence%29"><$c$c>find$p$pference() preferenceActivity 。铸 preference 你回到目录preference

To get at your ListPreference, call findPreference() on your PreferenceActivity. Cast the Preference you get back to ListPreference.

这篇关于是否有可能从一个适配器加载列表preference项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆