我有一个 AutoCompleteTextView,当您在 TextView 中键入内容时,它会给出一个建议列表。但是,当您选择建议时,您仍然必须按 Enter 键,不仅要从屏幕上移除键盘,还要提交您选择的建议。我正在尝试删除按 Enter 的这个额外步骤,因为用户没有在我的应用程序中建立连接,他们在 TextView 中选择建议后必须按 Enter 键。有什么建议/帮助吗?
这是我得到的建议,但似乎没有用。
element_image = (ImageView) findViewById(R.id.element_bullet);
//Get the string array of the radionuclide names that will auto complete.
radionuclideNames = getResources().getStringArray(R.array.radionuclide_names);
//Get a reference to the AutoCompleteTextView in the layout.
radionuclideTextView = (AutoCompleteTextView) findViewById(R.id.radionuclide_autocomplete);
//Create the adapter and set it to the AutoCompleteTextView.
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, radionuclideNames);
//Apply the adapter to the AutoCompleteTextView.
radionuclideTextView.setAdapter(adapter);
//Listen for when enter is pressed.
radionuclideTextView.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(parent.getId())
{
case R.id.radionuclide_autocomplete:
element_image.setImageResource(R.drawable.selectedbulletstate);
break;
}
}
public void onNothingSelected(AdapterView<?> parent) {
//TODO:
}
});