问题
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