Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoComplete search on even one character android

I am using AutoComplete widget. It works fine for two characters search but doesen't work for one character. I want to auto complete work even when user enters only one character.

For example when I enter "1" it should show all list start with "1". Now its showing suggestions list for 2 characters for example "12".

Code:

zip.setOnFocusChangeListener(new OnFocusChangeListener() {          @Override         public void onFocusChange(View v, boolean hasFocus) {             if (hasFocus) {                 String url = "xxxxxxxxxxxxxxxxxxxxxxx";                 String from = "zip";                 new GetAutoComplete(url, from).execute();// getting list              }         }     });    ArrayAdapter<Integer> aa = new ArrayAdapter<Integer>(                 MyActivity.this, R.layout.list_item_of_zip,                 zip_codes);             zip.setAdapter(aa); // zip = autocomplete widget and zip_codes = arrayList 
like image 754
Sunny Avatar asked Apr 01 '12 18:04

Sunny


2 Answers

Set your completionThreshold to 1.

<AutoCompleteTextView      android:id="@+id/your_id"      android:layout_width="200dp"     android:layout_height="wrap_content"     android:completionThreshold="1" /> 

Or to do it dynamically use mAutoCompleteTextView.setThreshold(1).

http://developer.android.com/reference/android/widget/AutoCompleteTextView.html

like image 52
Jacob Phillips Avatar answered Oct 02 '22 13:10

Jacob Phillips


Makes the threshold as one so it starts from the first letter onwards. You can do that using:

mAutoCompleteTextView.setThreshold(1);  
like image 31
Sreekumar SH Avatar answered Oct 02 '22 14:10

Sreekumar SH