简体   繁体   English

为ListView自定义CheckedTextView

[英]Customize the CheckedTextView for ListView

As far as I know, the ListView embeds CheckedTextView to form the list, but every CheckedTextView has only one TextView and a CheckBox. 据我所知,ListView嵌入CheckedTextView以形成列表,但每个CheckedTextView只有一个TextView和一个CheckBox。 What I want to do is adding some TextViews to the CheckedTextView, like this: 我想要做的是在CheckedTextView中添加一些TextView,如下所示:


TextView | TextView | TextView | TextView | TextView | TextView | CheckBox| 复选框| ---- CheckedTextView ---- CheckedTextView


How to customize the CheckedTextView? 如何自定义CheckedTextView? Any help will be appreciated! 任何帮助将不胜感激!

For that you need to create a custom LinearLayout that implements Checkable and the create your row.xml using that custom LinearLayout which will work as Checkable . 为此你需要创建一个自定义LinearLayout实现Checkable和创建row.xml使用定制LinearLayout这将作为Checkable Here is a nice tutorial explaining the same with an example. Here是一个很好的教程,用一个例子来解释相同的内容。

I recommend creating a custom layout for your ListView, perhaps: 我建议您为ListView创建自定义布局,可能:

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

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/text3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

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

</LinearLayout>

Take the time to give this layout some personality. 花点时间给这个布局一些个性。 Now you can use a SimpleAdapter or SimpleCursorAdapter to bind unique strings to each TextView. 现在,您可以使用SimpleAdapterSimpleCursorAdapter将唯一字符串绑定到每个TextView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM