I am targeting android 2.1.
I have an EditTextPreference
that allows users to input some values. If the user inputs an empty value I want to redisplay the edit preference after displaying an error message to the user.
I can display the error message, but I can't redisplay the EditTextPreference
again.
My code goes somewhat like this:
public boolean onPreferenceChange(Preference preference, Object newValue) {
final EditTextPreference editPreference = (EditTextPreference) preference;
String value = editPreference.getText();
if (value != null && value.trim() != "") {
return true;
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("");
builder.setMessage("O comando nºao pode ser vazio.");
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
return false;
}
}