Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在列表视图中同时使用复选框和文本视图?_Android_Listview_Checkbox - Fatal编程技术网

Android 如何在列表视图中同时使用复选框和文本视图?

Android 如何在列表视图中同时使用复选框和文本视图?,android,listview,checkbox,Android,Listview,Checkbox,我将在列表视图中使用复选框和文本视图。我使用此xml代码来对齐ListView项: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <L

我将在列表视图中使用
复选框
文本视图
。我使用此xml代码来对齐
ListView
项:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >
        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <TextView
        android:id="@+id/textView_Item_Listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3dp"
        android:text="gfhfgh"
        android:textSize="25sp" />
</LinearLayout>


我希望将
TextView
向右对齐,将
复选框
向左对齐。

像这样将TextView添加到线性布局中

<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent" >

<CheckBox
    android:id="@+id/checkBox1"
    android:weight="0.5"
    android:layout_width="0dip"
    android:layout_height="wrap_content" />


<TextView
android:id="@+id/textView_Item_Listview"
android:weight="0.5"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:textSize="25sp" />

</LinearLayout>

像这样将文本视图添加到线性布局

<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent" >

<CheckBox
    android:id="@+id/checkBox1"
    android:weight="0.5"
    android:layout_width="0dip"
    android:layout_height="wrap_content" />


<TextView
android:id="@+id/textView_Item_Listview"
android:weight="0.5"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:textSize="25sp" />

</LinearLayout>

您不需要如此复杂的布局。复选框提供您需要的所有元素。您可以使用以下选项:

<CheckBox
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="someText"
    android:button="@null"
    android:drawableLeft="@drawable/someDrawable"/>

您不需要如此复杂的布局。复选框提供您需要的所有元素。您可以使用以下选项:

<CheckBox
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="someText"
    android:button="@null"
    android:drawableLeft="@drawable/someDrawable"/>

您可以使用
RelativeLayout
,例如

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal" >

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:alignParentLeft="true">

<TextView
    android:id="@+id/textView_Item_Listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="3dp"
    android:alignParentRight="true" 
    android:text="gfhfgh"
    android:textSize="25sp" />

</RelativeLayout


例如,您可以使用
RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal" >

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:alignParentLeft="true">

<TextView
    android:id="@+id/textView_Item_Listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="3dp"
    android:alignParentRight="true" 
    android:text="gfhfgh"
    android:textSize="25sp" />

</RelativeLayout

试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

  <LinearLayout
    android:gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
  </LinearLayout>

  <TextView
    android:id="@+id/textView_Item_Listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="3dp"
    android:text="gfhfgh"
    android:textSize="25sp" />

</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

  <CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="gfhfgh" />

</LinearLayout>

您可以将文本设置为
复选框
,而不使用其他
文本视图

试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

  <LinearLayout
    android:gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
  </LinearLayout>

  <TextView
    android:id="@+id/textView_Item_Listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="3dp"
    android:text="gfhfgh"
    android:textSize="25sp" />

</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="5" >

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight="1"/>

    <TextView
        android:id="@+id/textView_Item_Listview"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:padding="3dp"
        android:text="gfhfgh"
        android:layout_weight="4"
        android:textSize="25sp" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

  <CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="gfhfgh" />

</LinearLayout>

您可以将文本设置为
复选框
,而不使用其他
文本视图


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="5" >

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight="1"/>

    <TextView
        android:id="@+id/textView_Item_Listview"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:padding="3dp"
        android:text="gfhfgh"
        android:layout_weight="4"
        android:textSize="25sp" />
</LinearLayout>


为什么您甚至需要
文本视图
CheckBox
TextView
的扩展,它本身支持android:text
。由于我们讨论的是
列表视图
,您可能还想签出。我想使用复选框来选择和删除列表视图项目您说得对。我现在无法在列表视图中触摸文本视图为什么您甚至需要
TextView
CheckBox
TextView
的扩展,它本身支持android:text
。由于我们讨论的是
列表视图
,您可能还想签出。我想使用复选框来选择和删除列表视图项目您说得对。我现在不能在列表视图中触摸文本视图谢谢。我使用它并将(android:gravity=“right”)添加到文本视图代码中。它解决了Draks:我现在不能触摸文本视图。我可以触摸复选框并选中它,但Onclicklistener现在不工作使用
onCheckedchangeListener
为您的
复选框
我为listview编写了一个McClickListener事件,表示现在不工作。我可以触摸复选框并选中它谢谢您。我使用它并添加(android:gravity=“right”)我现在不能触摸文本视图。我可以触摸复选框并选中它,但Onclicklistener现在不工作为您的
复选框使用
onCheckedchangeListener
,我为listview编写了一个McClickListener事件,表示现在不工作。我可以触摸复选框并选中它