2

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

现在看起来像这样:

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

谢谢

4

1 回答 1

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)

于 2011-08-28T17:46:12.107 回答