Auto populate second EditText based on first EditText input

582 Views Asked by At

I'm brainstorming the next phase of my project, and I'm not certain which path to take. My idea is to have 2 EditText fields, one beneath the other. When the user types a unique ID into the first field, the second field will populate automatically with corresponding text. For example, entering "X5432" in box 1 will put "1957 Thunderbird" in box 2. I estimate having about 500 value pairs to work from, so I assume a SQLite structure would be better than just using arrays. Any suggestions would be appreciated. Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

I think you should use TextWatcher.

  1. Just get value from edittext1

  2. Find appropriate text for edittext2

  3. Set text to second edittext.

    edittext.addTextChangedListener(new TextWatcher() {
    
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // do some stuff
    
        }
    
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // do some stuff
    
        }
    
        @Override
        public void afterTextChanged(Editable s) {
            // do some stuff
    
        }
    });