[英]Android Spinner Does Not Show Items When click it
I'm trying to create a dynamic spinner (combobox), but I couldn't make it work, it is showing the first item in the spinner, but when I click it, the list with the other items is not showing and nothing is happening.我正在尝试创建一个动态微调器(组合框),但我无法使其工作,它显示微调器中的第一个项目,但是当我单击它时,其他项目的列表没有显示,什么也没有发生。
My activity xml:我的活动xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="80dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/global_languages"/>
<Spinner
android:id="@+id/localesSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:popupBackground="@color/facebookBlue"
android:clickable="true"/>
</LinearLayout>
I'm trying to set items this way:我正在尝试以这种方式设置项目:
private void loadLocalesSuccess(Collection<String> locales){
Spinner localesSpinner = (Spinner) findViewById(R.id.localesSpinner);
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, new ArrayList(locales));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
localesSpinner.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
what could be the problem?可能是什么问题呢?
This code snippet should work, check if the data is proper.这个代码片段应该可以工作,检查数据是否正确。
ArrayList<String> locales = new ArrayList<>();
locales.add("English");
locales.add("French");
Spinner localesSpinner = findViewById(R.id.localesSpinner);
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, locales);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
localesSpinner.setAdapter(adapter);
adapter.notifyDataSetChanged();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.