5

ArrayAdapter를 사용하여 AutocompleteTextView의 목록을 동적으로 업데이트하려고합니다. 이 뷰를 업데이트하기 위해 AutocompleteTextView에서 발생할 수있는 변경 사항을 TextWatcher를 사용하여 모니터링합니다.ArrayAdapter 및 TextWatcher를 사용하는 동적 AutocompleTextView

문제는 목록이 전혀 업데이트되지 않고 그 이유를 이해할 수 없다는 것입니다. 나는 인터넷에서 그와 같은 것을 찾고 있었고 몇 가지 다른 접근법을 발견했지만 여전히 가장 간단한 것이어야하는 이유를 이해할 수 없다. 모든 설명은 크게 감사 할 것입니다.

대상 AVD : 구글 API를, 여기에

2.3.3는 간단한 코드 안드로이드 10 레벨 : TextWatcher는 AutoCompleteTextView에 공급되는 소스 코드에서

public class AutocompleteActivity extends Activity implements TextWatcher { 
    ArrayAdapter<String> adapter = null; 
    AutoCompleteTextView acTextView = null; 
    ArrayList<String> addresses = new ArrayList<String>(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.autocompleteview); 

     acTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete_address); 
     adapter = new ArrayAdapter<String>(this, R.layout.listitem, addresses); 
     adapter.setNotifyOnChange(true); 
     acTextView.addTextChangedListener(this); 
     acTextView.setAdapter(adapter); 
    } 

    @Override 
    public void onTextChanged(CharSequence text, int start, int before, int after) { 
     try { 
      adapter.add("test"); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
+0

nvm, 작동 :-( – gioski

+0

나는 비슷한 것을하고 있습니다 !!! http://stackoverflow.com/questions/12854336/autocompletetview-backed-by-cursorloader – toobsco42

답변

3

, 이것은 진짜 문제는 .

AutoCompleteTextView 소스 코드를 보면 AutoCompleteTextView에 자신의 TextWatcher 인 "MyWatcher"가 있습니다. 이 때문에 AutoCompleteTextView는 타이핑 작업을 되돌릴 수 없습니다.