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

徘徊边缘 提交于 2019-12-02 09:55:47

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<String> adapter = new ArrayAdapter<String>(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.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!