Combine Spinner and AutoCompleteTextView

匿名 (未验证) 提交于 2019-12-03 02:51:02

问题:

I am asking myself if it is possible, to combine a Spinner and a AutoCompleteTextView. Basically I want an AutoCompleteTextView, that shows all entries from Array when I click it.

Does anybody know how to do that?

回答1:

Try this code:

 ArrayAdapter myAdapter = new ArrayAdapter<String>(this,                     android.R.layout.simple_dropdown_item_1line, YOUR_ARRAY);     myAutoCompleteTextView.setAdapter(myAdapter ); 


回答2:

Just found out that this does exactly what I was asking for:

final AutoCompleteTextView textView;     final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(             getActivity(), android.R.layout.simple_dropdown_item_1line,             getResources().getStringArray(R.array.names));      textView = (AutoCompleteTextView) v.findViewById(R.id.txtViewNames);     textView.setAdapter(arrayAdapter);     textView.setOnClickListener(new View.OnClickListener() {         @Override         public void onClick(final View arg0) {             textView.showDropDown();         }     }); 


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