如何像 Spinner 一样使用 autoCompleteTextView 作为下拉列表?

问题描述

当我制作下拉列表时,我使用微调器制作它,但由于它缺少许多选项,而且我不想经历制作自定义列表的麻烦,我选择了 autoCompleteTextView从下拉列表的材料库中继承材料样式。

这是我的代码

   adaptor_tool.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    toolNo.setAdapter(adaptor_tool);
    toolNo.setonItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int position,long id) {
            Toast.makeText(toolSettings.this,""+position,Toast.LENGTH_SHORT).show();
            configurations.setToolNo(toolNo.getSelectedItemPosition());
            if(configurations.setToolNo(position+1) == 0)
            {
                Toast.makeText(toolSettings.this,"Invalid tool number\n setting to default tool 1",Toast.LENGTH_SHORT).show();
            }

        }

        @Override
        public void onnothingSelected(AdapterView<?> parent) {

        }
    });

这是我使用微调器的时候。现在这是我使用 autoCompleteTextView 的时候:

autotxt.setAdapter(adaptor_tool);
    autotxt.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence,int i,int i1,int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence,int i2) {

            for (String string : toolNum)
                if (string.toLowerCase().equals(charSequence.toString().toLowerCase())) {
                    int pos = toolNum.indexOf(string);
                    configurations.setToolNo(?);
                }

        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

在 (?) 的位置我应该写什么,例如如何在给定位置为方法 configurations.setToolNo(-------) 提供项目?

我尝试使用 onItemClickListner,但没有用,而且 autoCompleteTextView 无法使用 getSelectedItemPosition()。我想要所选位置的项目。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)