Senthil Mg
Senthil Mg

Reputation: 3313

Need help on AutoCompleteTextView for Searching

I have implemented an AutoCompleteTextView for searching. Is AutoCompleteTextView supported in all SDK versions and targets, because when I tried this sample it shows an empty dropdown list. When I used the same in my application for parsed content placed inside a string array, I'm getting an Exception.

Log.v("Length of a",Integer.toString(a.length));
try{
    wv.setVisibility(View.GONE);
    place_list.setVisibility(View.VISIBLE);
    Log.v("Length of a222222",Integer.toString(a.length));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(Bru_Maps.this, android.R.layout.simple_dropdown_item_1line, a);
    textView.setAdapter(adapter);
} catch(Exception e) {                  
    Log.v("Error","search_name"+e);     
}

The above given code prints the log well but it returns a NullPointerException.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(Bru_Maps.this, android.R.layout.simple_dropdown_item_1line, a);

Upvotes: 2

Views: 1031

Answers (2)

Ragunath Jawahar
Ragunath Jawahar

Reputation: 19723

As I can see from the example, you need to set the Threshold value to 1, if you want to see the list of available countries after you type the first character in the TextView. Use autoCompleteTextView.setThreshold(1) to see it in action.

Upvotes: 5

Eliseo
Eliseo

Reputation: 1557

Can't add comments yet, so... What is the datatype for a? You wrote that it is a string when it needs to be an array of strings.

Upvotes: 0

Related Questions