Android Preferences自定义布局编辑

时间:2011-08-28 17:18:29

标签: android layout textview preferences preferenceactivity

我在自己的偏好中添加了自定义布局。但是现在我想以编程方式更改布局中TextView的文本。我该怎么做?

现在看起来像这样:

final PreferenceScreen preference = (PreferenceScreen) findPreference(getString(R.string.key_of_my_prefernce));
preference.setLayoutResource(R.layout.my_preference);

谢谢

1 个答案:

答案 0 :(得分:1)

你试过吗?

PreferenceManager prefmngr=preference.getPreferenceManager();
TextView txt = (TextView)prefmngr.findPreference("the key of the textview in the preference tree").getView(convertView, parent);
txt.setText("TEXT");

http://developer.android.com/reference/android/preference/Preference.html#getView(android.view.View,android.view.ViewGroup)