Android上EditText偏好设置的动态数量

时间:2012-07-03 04:16:12

标签: android android-preferences

我正在寻找一种方法来创建动态数量的EditTextPreference s。

我目前正在创建一个扩展PreferenceActivity的首选项活动,并以XML格式创建所有按钮。

我的问题是我有第二个偏好设置屏幕,我希望用户设置一个新的“团队”。

首先选择团队中有多少成员(可能是列表首选项或其他文本偏好),并为每个成员显示两个EditTextPreference(名称和ID)。

但我似乎无法找到解决这个问题的方法。

1 个答案:

答案 0 :(得分:0)

嗯,您需要获取所需的EditTextPreferences数量,然后将它们全部添加到新的LinearLayout中。这样的事可能

LinearLayout parent = ((LinearLayout)findViewById(R.id.PUTLAYOUTNAMEHERE));
for (int i=0; i<NUMEDITTEXTPREFERENCES; i++)
{
    EditTextPreferences newView = new EditTextPreferences(this); //Must be written inside an activity.
    parent.addView(newView);
}