1

I have a TextView and I want to control when the user insert a letter.

Ex.

s -> search s in database and show results
st -> search st in database and show results
sta -> search sta in database and show results
stac -> search stac in database and show results
stack -> search stack in database and show results
...
...
...

How I can do this ?

Matteo Cardellini
  • 876
  • 2
  • 17
  • 41
  • See this question: http://stackoverflow.com/questions/4304075/android-how-can-i-get-edittext-change – David Merriman Feb 01 '12 at 19:17
  • 1
    You many need to use TextChangedListener with textWatcher. see this discussion http://stackoverflow.com/questions/4310525/android-on-edittext-changed-listener – kosa Feb 01 '12 at 19:18

1 Answers1

2

User TextWatcher to get Text when user enter any text in EditText

searchText.addTextChangedListener(new TextWatcher() {

                public void afterTextChanged(Editable s) {

                        String text = searchText.getText().toString();
                        if (text != null && text.length() > 0) {
                                                // Call your method that will get Data from Database and then update then data to the ListView or anything you want
                            getSearchDataFromDBagianUserText(text); 
                        }

                }

                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                }

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

                }
            });
Arslan Anwar
  • 18,746
  • 19
  • 76
  • 105