如何在列表视图中一起使用checkbox和textview?

时间:2015-09-28 11:57:58

标签: android listview checkbox

我将在列表视图中使用CheckBoxTextView。我使用这个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对齐,CheckBox左对齐。

5 个答案:

答案 0 :(得分:1)

将textview添加到linearlayout,就像这样

 <input type="text" id="one" value="20" />
 <input type="text" id="two" value="30" />

答案 1 :(得分:1)

您不需要这么复杂的布局。 Checkbox提供您需要的所有元素。你可以用这个:

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

答案 2 :(得分:1)

您可以使用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

答案 3 :(得分:1)

试试这个......

function initTable(userJvmsArray) {
            var collumnsCallbacks = [{
                title: "Username",
                data: "username"
            }];

            for (var i = 0; i < $scope.unique.length; i++) {
                $('#nameColumn').after('<th>' + $scope.unique[i] + '</th>');
                var jvm = $scope.unique[i];
                var col = {
                    title: jvm,
                    data: function(data, type, row) {
                        var data2 = data;
                        var jvms = $scope.unique;
                        for (var k = 1; k < jvms.length; k++) {
                            console.log(jvms);
                            for (var j = 0; j < data2.myarray.length; j++) {
                                if (table.column(k).title() == data2.myarray[j].Name) {
                                    console.log(table.column(k).title() + " = " + data2.myarray[j].Name + " YES");
                                    return "yes";
                                } else {
                                console.log(table.column(k).title() + " = " + data2.myarray[j].Name + " NO");
                                    return "no";
                                }
                            }
                        }


                    }
                };
                collumnsCallbacks.push(col);
                $scope.columns = collumnsCallbacks;
            }
            $scope.myTable = $('#myTable').DataTable({
                'paging': true,
                "pageLength": 3,
                'columns': collumnsCallbacks
            });

["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user1: myword = myword YES myctrl.controller.js:66
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user1: myword = myword YES myctrl.controller.js:66

["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user11: myword = secondword NO myctrl.controller.js:69
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user11: myword = secondword NO myctrl.controller.js:69

["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user1: myword = myword YES myctrl.controller.js:66
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user11: myword = secondword NO myctrl.controller.js:69

["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user1: myword = myword YES myctrl.controller.js:66
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user11: myword = secondword NO myctrl.controller.js:69
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user1: myword = myword YES myctrl.controller.js:66
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user1: myword = myword YES myctrl.controller.js:66
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user11: myword = secondword NO myctrl.controller.js:69
["myword", "secondword", fastLoop: function, fastLoopAsc: function] myctrl.controller.js:63
user11: myword = secondword NO 

您可以将文字设置为<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>

答案 4 :(得分:1)

= IFERROR((Sales - Expense) / Sales, 0)