getting list of previously entered strings under the edit-text in android “just like a username field of some email/website”

后端 未结 1 1772
离开以前
离开以前 2021-01-28 07:00

I want some directions. I have not much clear understanding about it. So please...

  1. Here is my edit-text in xml form:

     
    
            
1条回答
  •  北海茫月
    2021-01-28 07:49

    You are most of the way there. I recommend using an AutoCompleteTextView and simply binding your List to an ArrayAdapter. (An AutoCompleteTextView already has the dropdown feature to help the user select between similar entries and doesn't require a TextWatcher.)

    Code from documentation:

     public class CountriesActivity extends Activity {
         protected void onCreate(Bundle icicle) {
             super.onCreate(icicle);
             setContentView(R.layout.countries);
    
             ArrayAdapter adapter = new ArrayAdapter(this,
                     android.R.layout.simple_dropdown_item_1line, COUNTRIES);
             AutoCompleteTextView textView = (AutoCompleteTextView)
                     findViewById(R.id.countries_list);
             textView.setAdapter(adapter);
         }
    
         private static final String[] COUNTRIES = new String[] {
             "Belgium", "France", "Italy", "Germany", "Spain"
         };
     }
    

    (You can use your ArrayList in an identical manner to the primitive Array above.)

    0 讨论(0)
提交回复
热议问题