我们如何验证输入到EditBoxPrefence中的值?
例如,用户输入类似
的目录名称myfolder //或/ myfolder或
我想修剪任何斜线,然后存储首选项的值 怎么可能?
答案 0 :(得分:1)
您可以测试该值并告诉用户出错的地方: 或做任何你想做的事情
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Your_Pref = (EditTextPreference) getPreferenceScreen().findPreference("Your_Pref");
Your_Pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Boolean rtnval = true;
if (Your_Test) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Invalid Input");
builder.setMessage("Something's gone wrong...");
builder.setPositiveButton(android.R.string.ok, null);
builder.show();
rtnval = false;
}
return rtnval;
}
});
}