如何解决如何像 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 举报,一经查实,本站将立刻删除。