Hot questions for Using Android EditText in autocomplete

Question:

I am working on a contact manager project for android.In which i want to auto-fill the email address ending part in the field at the time of signup by the user. For example when user type his or her username it should be automatically gives the suggestion for @gmail.com or @outlook.com and so on.

Well,This is a little part of my code

String[] maindb = {"@gmail.com", "@rediffmail.com", "@hotmail.com", "@outlook.com"};

mail = (AutoCompleteTextView) findViewById(R.id.A1_edt_mail);

ArrayAdapter<String> adpt = new ArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item, maindb);
mail.setAdapter(adpt);

Well, I got output like this

But I want that when user enter his/her username then this suggestion should be appear but it din't.

Well, My question is not duplicate of android how an EditText work as AutoComplete this question.My problem is differ from this.

Thanks in advance.


Answer:

I suggest that you append the text from email to each string in your maindb before setting the adapter --> use TextWatcher to detect changes on mail view .

Edit

may be this what you are looking for

final ArrayList<String> maindb = new ArrayList<>();
    maindb.add("@gmail.com");
    maindb.add("@rediffmail.com");
    maindb.add("@hotmail.com");
    maindb.add("@outlook.com");
    final ArrayList<String> compare = new ArrayList<>();
    final ArrayAdapter<String> adpt = new ArrayAdapter<String>(MainActivity.this, R.layout.support_simple_spinner_dropdown_item, compare);
    Word.setAdapter(adpt);
    Word.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() >= 0)
                if (!s.toString().contains("@")) {
                    compare.clear();
                    for (String aMaindb : maindb) {
                        aMaindb = s + aMaindb;
                        compare.add(aMaindb);
                    }
                    adpt.clear();
                    adpt.addAll(compare);
                }
        }
    });

Hope this will help

Question:

On a MultiAutoCompleteTextView in android I am able to add entries and parse them just fine. After auto completing the most recent item, when I press backspace it will delete all the characters before I autocompleted the item. Great. Now my problem is when I have multiple entries already autocompleted. I want to be able to delete each entry with a single backspace rather than deleting each character individually. I have tried using a TextWatcher but couldn't really get that to go anywhere. Is there a way I could tokenize each entry as its own entity rather than appending it to a string (like google hangouts and facebook do. Note: this isn't a requirement, just a thought of how i could do it). Thanks for any help! I'll post here if I find out more.


Answer:

I ended up using this library

https://github.com/splitwise/TokenAutoComplete

Allows to use any view as the token and allows a token to be added and deleted as one entity.

Question:

I have an EditText in a layout. I want to "allow" the user to be able to enter only a string that is part of a predefined set of string I have (an array of 8 strings). How would I show the user the only options to type that are the ones part of my list of 8 string when he presses in my EdiText?


Answer:

This one should help: http://developer.android.com/reference/android/widget/AutoCompleteTextView.html also you may need to add a textchange listener.