Customize the CheckedTextView for ListView

不打扰是莪最后的温柔 提交于 2019-12-10 23:37:44

问题


As far as I know, the ListView embeds CheckedTextView to form the list, but every CheckedTextView has only one TextView and a CheckBox. What I want to do is adding some TextViews to the CheckedTextView, like this:


TextView | TextView | TextView | CheckBox| ---- CheckedTextView


How to customize the CheckedTextView? Any help will be appreciated!


回答1:


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. Here is a nice tutorial explaining the same with an example.




回答2:


I recommend creating a custom layout for your ListView, perhaps:

<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.



来源:https://stackoverflow.com/questions/12048145/customize-the-checkedtextview-for-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!