将AutoCompleteTextView与一个button组合起来,做成一个可以输入,也可以选择的下拉框。
下面是定义的xml文件,auto_spinner.xml:
1 29 10 21 22 23 24 25 32 33
这是部分代码:
…… private void init(Context context) { // this.context = context; LayoutInflater.from(context).inflate(R.layout.auto_spinner, this); adapter = new ArrayAdapter(context, android.R.layout.simple_dropdown_item_1line, list); text = (AutoCompleteTextView) this.findViewById(R.id.repeateMode); text.setAdapter(adapter); button = (ImageButton) this.findViewById(R.id.repeateModeBtn); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 显示下拉框 text.showDropDown(); } }); }
这样基本几可以了。