如何在打开的首选项屏幕上打开EditTextPreference

时间:2012-06-06 10:20:59

标签: android edittextpreference

我打开Preference屏幕时打开EditTextPreference。我试试

mLabel = (EditTextPreference) findPreference("labelKey");
mLabel.getDialog().show() // this does not work. getDialog return null
mLable.getEditText().requestFocus(); // this does not work too.

我该怎么做?

1 个答案:

答案 0 :(得分:3)

如果我理解正确,您需要在打开首选项后立即在首选项屏幕中打开一个首选项(??)。

您可能需要查看此内容:https://stackoverflow.com/a/4869034/668240

// the preference screen your item is in must be known
PreferenceScreen screen = (PreferenceScreen) findPreference("pref_key");

// the position of your item inside the preference screen above
int pos = findPreference("abc").getOrder();

// simulate a click / call it!!
screen.onItemClick( null, null, pos, 0 );