0

In my project settings there is an EditTextPreference which is used to change the username but I don't want the user to set a username less than 4 characters.

Is there any way to limit the user input or to make rules for the value input in EditTextPreference?

Sufian
  • 6,405
  • 16
  • 66
  • 120
  • http://stackoverflow.com/questions/17781553/how-to-set-min-textmandatory-and-max-text-in-edittext maybe this can help – R. Adang Aug 31 '16 at 09:50
  • Please be aware that `SharedPreferences` can be edited on rooted devices. So you are opening a door for nasty surprises, as far as I understand. Also what you want to achieve, I think you will either have to subclass `EditTextPreference` or put a check in your `OnPreferenceChangeListener`. – Sufian Aug 31 '16 at 09:51
  • In your preference activity you can use either text watcher for edittextpreference or you can check it in onPreferenceChange method – Vickyexpert Aug 31 '16 at 09:53
  • Maybe this answer is something from which you can take some idea - http://stackoverflow.com/a/18103350/1276636 – Sufian Aug 31 '16 at 09:54
  • @Sufian but What is the best way to store the username and password securely in android studio which also can be modified by user from the the app – Karamantina Aug 31 '16 at 10:19
  • @Karamantina firstly, your will store it on an Android device, not Android Studio. :) Secondly, you'll have to store username/password encrypted. For that, you can use `SecurePreferences`. See this GitHub link for more info - https://github.com/sveinungkb/encrypted-userprefs – Sufian Aug 31 '16 at 10:28
  • Thanks @Sufian and sorry for mistakes, English is not my mother tongue ,I meant in my question how to do the codding in Android studio not the data storing >_ – Karamantina Aug 31 '16 at 10:49

1 Answers1

0

Try to use this:

Button btnCheckUsername = (Button) findViewById(R.id.btnLogin);
EditText et = (EditText) findViewById(R.id.editTextUsername);
    et.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.length() < 4)
            {
                btnCheckUsername.setEnabled(false);
            } else
            {
                btnCheckUsername.setEnabled(true);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

For EditTextPreferences this may help you :)

Community
  • 1
  • 1
jdstaerk
  • 882
  • 1
  • 13
  • 30
  • This way at the login activity .. My question is how to do similar to this thing but with `EditTextPreference` Dialog – Karamantina Aug 31 '16 at 10:23