其他分享
首页 > 其他分享> > android-如何在打开首选项屏幕上打开EditTextPreference

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

作者:互联网

打开“首选项”屏幕时,我想打开EditTextPreference.我尝试

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

我怎样才能做到这一点?

解决方法:

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

您可能要看一下: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 ); 

标签:edittextpreference,android
来源: https://codeday.me/bug/20191201/2079325.html