tags:

views:

38

answers:

2

hi i am new to android what i did is creating a list with strings and implementing the search using edit text,my code for this is as fallows

 ((EditText)findViewById(R.id.EditText01)).setOnKeyListener(new OnKeyListener() 
    {

  public boolean onKey(View v, int keyCode, KeyEvent event)
  { String enteredText = ((EditText)findViewById(R.id.EditText01)).getText().toString();

      Iterator<String> strIt = strList.iterator();
    while(strIt.hasNext()){
      String str = strIt.next();

      if(str.startsWith(enteredText)){


       match.add(str);

     } 
     }

     } 

it works when focus is changed form edit text,but i need to work it like quick search box.when ever i enter a letter in edit text,the matching words will be displayed.how can i done this.pls post some code.Thank u in advance.

A: 

Take a Look at AutoCompleteTextView.

Basically you can create an ArrayAdapter or a SimpleAdapter that contains your Strings. Then just replace your EditText with the AutoCompleteTextView and automagically ... you get the typeahead behavior that you describe.

Greg
but i need to display all the items that come in the hint in a text view.Is it possible to do it
MaheshBabu
AutocompleteTextView will create TextView list that has all the possible words that match your strings. Is this what you want?
Greg
A: 

try implementing TextWatcher interface.

it has 3 methods which u need to override.

public void afterTextChanged(Editable s) {

    Log.v("afterTextChanged","here");
}
public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {

    Log.v("beforeTextChanged","here");
}

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

i think this will do ur work.

ninad