gpt4 book ai didi

java - Android Spinner 不显示下拉菜单

转载 作者:太空宇宙 更新时间:2023-11-04 10:12:17 29 4
gpt4 key购买 nike

我尝试在 FrameLayout 中显示微调器,但它没有显示下拉菜单。我找不到问题。

XML

 <FrameLayout
//design continue here
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5b89ff"
android:orientation="vertical">
<Spinner
android:id="@+id/spinner"
android:spinnerMode="dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

</LinearLayout>
</FrameLayout>`

Code

final List<String> list=new ArrayList<>();

list.add("jamshaid");
list.add("jamshaid");
list.add("jamshaid");
list.add("jamshaid");
list.add("jamshaid");

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_item, list);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(arrayAdapter);

My onCreate method

TabHost host; 
host = findViewById(R.id.tabHost);
spinner= findViewById(R.id.spinner);
progressDialog=new ProgressDialog(this);
host.setup();
//Tab 1
TabHost.TabSpec spec = host.newTabSpec("News Feed");
spec.setContent(R.id.tab1);
spec.setIndicator("News Feed");
host.addTab(spec);`

更新 1

使用RelativeLayout而不是FrameLayout会抛出
android.widget.RelativeLayout 无法转换为 android.widget.FrameLayout

最佳答案

删除此行并检查,

arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //Comment this line

Try this change also :

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_dropdown_item, list); //Changed layout resource id

关于java - Android Spinner 不显示下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52164502/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com