我正在尝试让我的AutoCompleteTextView显示结果,但无论我寻找什么样的示例或解决方案,我都无法让它显示结果。我在调试中检查了它,并且适配器中包含所有值但它不会显示下拉
main.xml中
<AutoCompleteTextView
android:id="@+id/spinnerDropDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/primary_text_light"/>
Main.java
spinnerdropdown = (AutoCompleteTextView) findViewById(R.id.spinnerDropDown);
setContentView(R.layout.main);
ArrayAdapter<String> stringArrayAdapter=
new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line,
locations
);
spinnerdropdown.setThreshold(0);
stringArrayAdapter.notifyDataSetChanged();
spinnerdropdown.setAdapter(stringArrayAdapter);
spinnerdropdown.setTextColor(Color.RED);
locations是一个String ArrayList
答案 0 :(得分:1)
setContentView(R.layout.main);
spinnerdropdown = (AutoCompleteTextView) findViewById(R.id.spinnerDropDown);
ArrayAdapter<String> stringArrayAdapter=
new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line,
locations
);
spinnerdropdown.setThreshold(1);
spinnerdropdown.setAdapter(stringArrayAdapter);
spinnerdropdown.setTextColor(Color.RED);
答案 1 :(得分:1)
试试这个,它有效。
setContentView(R.layout.main);
spinnerdropdown = (AutoCompleteTextView) findViewById(R.id.spinnerDropDown);
stringArrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, languages);
spinnerdropdown.setThreshold(0);
stringArrayAdapter.notifyDataSetChanged();
spinnerdropdown.setAdapter(stringArrayAdapter);
spinnerdropdown.setTextColor(Color.RED);