How to set Adapter to Auto Complete Text view?

前端 未结 2 674
忘了有多久
忘了有多久 2020-12-20 16:39

I need adapter data set to the auto complete text view in android .

2条回答
  •  既然无缘
    2020-12-20 17:27

    Create one project for AutoCompleteTextView and paste the code to required place -

    main.xml

    
    
    
    
    
    

    AutoCompleteTextview.java

    public class AndroidAutoCompleteTextView extends Activity implements TextWatcher{
    
    AutoCompleteTextView myAutoComplete;
    String item[]={
      "January", "February", "March", "April",
      "May", "June", "July", "August",
      "September", "October", "November", "December"
    };
    
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    
       myAutoComplete = (AutoCompleteTextView)findViewById(R.id.myautocomplete);
    
       myAutoComplete.addTextChangedListener(this);
       myAutoComplete.setAdapter(new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, item));
    
       }
    
    @Override
    public void afterTextChanged(Editable arg0) {
     // TODO Auto-generated method stub
    
    }
    
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
     // TODO Auto-generated method stub
    
    }
    
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
     // TODO Auto-generated method stub
    
    }
    }
    

    Just use this example. And, figure out how they're setting adapter to AutoComplete TextView Hope this helps you.

提交回复
热议问题