android微调器下拉菜单自定义

android微调器下拉菜单自定义,android,spinner,Android,Spinner,我使用微调器显示某些内容,这是我的代码: ArrayAdapter<ClassName> adapter = new ArrayAdapter<ClassName>(getActivity(), android.R.layout.simple_spinner_dropdown_item, nameList); adapter.setDropDownViewResource(android.R.layout.simple_list_item_

我使用微调器显示某些内容,这是我的代码:

ArrayAdapter<ClassName> adapter = new ArrayAdapter<ClassName>(getActivity(), android.R.layout.simple_spinner_dropdown_item, nameList);
                adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
使用此代码,当单击微调器时,我可以看到文本和复选框。 之后,我尝试如下自定义微调器:

ArrayAdapter<ClassName> adapter = new ArrayAdapter<ClassName>(getActivity(),
                        R.layout.list_spinner, tenfavList);
                adapter.setDropDownViewResource(R.layout.list_spinner_dropdown);
这是list_spinner_dropdown.xml:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:singleLine="true"
android:ellipsize="end"
android:textColor="#0004ff"
android:textSize="@dimen/20sp"/>
但使用此代码时,单击微调器时,我只看到文本,没有复选框。
如何修复它?

好的,现在我知道你的问题了。问题仅在于,请在CheckedTextView中为选中或未选中添加样式,如:

在res/drawable中添加文件default_checkbox.xml

<?xml version="1.0" encoding="utf-8"?>

在Xml中:

 <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAllCaps="true"
        android:singleLine="true"
        android:ellipsize="end"
        android:checked="true"
        android:checkMark="@drawable/default_checkbox"
        android:text="sdfsdfsdfsdfdsfdsf"
        android:textColor="#0004ff"
        android:textSize="25dp"/>

请把你想做的事写清楚。。这里没有明确说明您要设置复选框或spiner。。为什么使用选中的textview而不是spinner?我的意思是,当单击spinner时,会显示下拉列表,并且带有文本,带有复选框。但在这里,我看不到复选框,所以请使用微调器并在包含复选框的适配器中添加自定义布局。如果您愿意,我将为您提供一个示例链接是的,我的意思是,使用adapter.setDropDownViewResourceandroid.R.layout.simple\u list\u item\u single\u choice时也是这样;对不起,我的英语不好。我正在重写我的问题,对不起。请检查编辑后的答案,并让我知道它是否有用。在默认情况下,我看到元素项必须声明,这是错误。为什么?将选择器添加为根标记您是否准确地在drawable文件夹中添加了默认复选框,并根据选中或未选中更改复选框的图像?我很乐意为您提供帮助:
 <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAllCaps="true"
        android:singleLine="true"
        android:ellipsize="end"
        android:checked="true"
        android:checkMark="@drawable/default_checkbox"
        android:text="sdfsdfsdfsdfdsfdsf"
        android:textColor="#0004ff"
        android:textSize="25dp"/>