[英]MultiSelectListPreference setEntries doesn't show up
I am trying to build an android app and I need a MultiSelectListPreference
option in the settings menu. 我正在尝试构建一个Android应用,并且我需要在设置菜单中使用
MultiSelectListPreference
选项。 I have created a PreferenceActivity
to handle this and I created a preferences.xml
file as well, but I need to be able to load the list elements dynamically in the program. 我创建了一个
PreferenceActivity
来处理此问题,还创建了一个preferences.xml
文件,但是我需要能够在程序中动态加载列表元素。 I know that I need to use the setEntries
and setEntryValues
methods to do this, but when I use these methods no exceptions are thrown and the title and summary of the MultiSelectListPreferenc
show up but no elements appear. 我知道我需要使用
setEntries
和setEntryValues
方法来执行此操作,但是当我使用这些方法时,不会引发任何异常,并且MultiSelectListPreferenc
的标题和摘要会显示,但不会出现任何元素。
I have verified that the arrays I am using to populate entries
and entryValues
are not empty by printing them out, as well as by printing out the result of getEntries()
and getEntryValues()
after having set
them and both these show the entry list to be populated; 我已经验证了我用来填充
entries
和entryValues
的数组entryValues
为空, entryValues
是将它们打印出来,以及在set
完它们后打印出getEntries()
和getEntryValues()
的结果,并且这两个都将条目列表显示为被填充; however no elements show up. 但是没有元素出现。
My preferences.xml
code: 我的
preferences.xml
代码:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<MultiSelectListPreference
android:key="markedApps"
android:title="Targeted Apps"
android:summary="Select apps to conditionally disable" />
</PreferenceScreen>
My AppSettings.java
code: 我的
AppSettings.java
代码:
public class AppSettings extends PreferenceActivity {
public static MultiSelectListPreference blocked;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
blocked = new MultiSelectListPreference(this);
getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefFrag()).commit();
}
public static class PrefFrag extends PreferenceFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
MultiSelectListPreference blocked = (MultiSelectListPreference)findPreference("markedApps");
if (blocked == null)
Log.e("NullPointerException", "Blocked is null");
AppSelector.populateAppList();
CharSequence[] appNames = new CharSequence[AppSelector.Data.appNames.size()];
CharSequence[] allApps = new CharSequence[AppSelector.Data.allApps.size()];
int i = 0;
for (String appName : AppSelector.Data.appNames)
appNames[i++] = (CharSequence) appName;
i = 0;
for (String app : AppSelector.Data.allApps)
allApps[i++] = (CharSequence) app;
blocked.setEntries(appNames);
blocked.setEntryValues(allApps);
}
}
}
Thank you in advance for any help you provide. 预先感谢您提供的任何帮助。
Wow so I feel extremely stupid now. 哇,所以我现在感觉非常愚蠢。 Turns out my problem was that I expected the list to show up under the title and summary whereas you actually have to click on the title and summary to make the list pop up.
原来我的问题是我希望列表显示在标题和摘要下,而实际上您必须单击标题和摘要才能弹出列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.