I am trying to check the format of an input for an editText preference, in this case 24 hour format H:mm, and I want to force the edit dialog to appear again if there is an input format error.
My idea is using a OnPreferenceChange listener running on the Settings activity that implements the PreferenceScreen:
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//check 24 hour format
SharedPreferences myPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
String startTime= myPreferences.getString(PREF_FLAT_RATE_START, "18:00");
try{
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Date time = sdf.parse(startTime);
}catch (Exception e){ //If exception there is a format error...
Log.v("Settings", "rateTime not properly formatted");
---> Re Open Dialog from EditText key = PREF_FLAT_RATE_START <---
}
}
Is it possible? I've already tried to get the dialog from the findViewByid(EDITTEXT) but as it is not showing anymore when is runned I get a null pointer :(
Also I am not sure if this is the best way to check the input format for and HOUR and MINUTE.
Thanks!