2012-04-01 4 views
23

나는 AutoComplete 위젯을 사용 중입니다. 그것은 두 문자 검색에 대해서는 잘 작동하지만 한 문자에 대해서는 작동하지 않습니다. 사용자가 한 문자 만 입력해도 작업을 자동 완성하고 싶습니다.한 문자로만 자동 완성 검색 android

예를 들어 "1"을 입력하면 모든 목록 시작이 "1"로 표시되어야합니다. 이제 2 개의 문자 (예 : "12")에 대한 제안 목록이 표시됩니다.

코드 :

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 
+0

코드 대화 상대를 업데이트했습니다! – Sunny

+0

카운트 0에 무슨 뜻인지 이해가 안되네. 그런 건 없다. – Sunny

답변

66

설정하십시오 completionThreshold

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

1에 아니면 작업을 수행하는 동적 mAutoCompleteTextView.setThreshold(1)를 사용합니다. 하나는 그래서 이후 첫 글자에서 시작으로

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

7

는 임계 값을 만듭니다. 다음을 사용하여 수행 할 수 있습니다.

mAutoCompleteTextView.setThreshold(1);