设置为android:choiceMode=";时无法看到单选按钮;“单一选择”;
我刚刚看到了以下适合我的需要的东西,我正在努力找到让同样的东西为我的listview工作的方法。希望有人能告诉我这件事 这是链接的内容:设置为android:choiceMode=";时无法看到单选按钮;“单一选择”;,android,listview,radio-button,choice,Android,Listview,Radio Button,Choice,我刚刚看到了以下适合我的需要的东西,我正在努力找到让同样的东西为我的listview工作的方法。希望有人能告诉我这件事 这是链接的内容: android:choiceMode=“singleChoice”设置为listview仅设置单个单选按钮选择 现在我有一些类似于上面的listview的东西,但是有一些图像和文本视图,没有什么特别的 这是我的列表视图: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and
android:choiceMode=“singleChoice”
设置为listview
仅设置单个单选按钮选择
现在我有一些类似于上面的listview的东西,但是有一些图像和文本视图,没有什么特别的
这是我的列表视图:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background ="#CCCCCC">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:divider="#3366CC"
android:dividerHeight="2dp"
android:choiceMode="singleChoice"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:background="?android:attr/dividerVertical"
android:layout_alignParentTop="true"/>
<View
android:id="@+id/divider"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="?android:attr/dividerVertical"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/divider"
android:background="@drawable/buttons"
android:text="Previous"
android:layout_alignParentBottom="true"
android:textSize="20sp"
android:textColor="#4285f4"/>
<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/buttons"
android:text="Next"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/divider"
android:textSize="20sp"
android:textColor="#4285f4"/>
</RelativeLayout>
</LinearLayout>
现在我的问题是,我无法获得旁边的单选按钮,如上面的链接所示
这是我的row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/photo"
android:layout_width="150dip"
android:layout_height="100dip"
android:paddingRight="15dp"
android:paddingLeft="15dp"/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="160dp"
android:layout_marginTop="10dp"
android:descendantFocusability="blocksDescendants">
<TextView android:id="@+id/name"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/itemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:focusable="false"/>
<TextView android:id="@+id/price"
android:textSize="19sp"
android:textStyle="bold"
android:textColor="#003399"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/itemDescription"/>
</RelativeLayout>
</RelativeLayout>
您链接到的示例对行使用了
android.R.layout.simple\u list\u item\u single\u选项。你不是。显示单选按钮是因为示例使用的是android.R.layout.simple\u list\u item\u single\u choice
和singleChoice
ListView
singleChoice
单独不添加单选按钮
您需要直接使用RadioButton
或使用CheckedTextView
为行创建(或查找)一个自定义视图,该视图实现了可检查
界面,并在其中有一个合适的单选按钮
例如,它利用您提供的CheckedTextView
来提供checkeable
界面,以使用singleChoice
ListView
如果要从ListView中的所有条目中选择单行,则不要使用复选框。只使用单选按钮。不要使用singlechoice listview,因为它不支持自定义行,它只支持android默认布局,即android.R.layout.simple\u list\u item\u single\u choice。因此,最好在每一行上创建带有单选按钮的自定义listview。并通过代码尝试管理单个选择。我想这会帮助你更好地工作。如果你需要更多的帮助,请告诉我