I use adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, cur, cols, views) to create a multiple choice control, but I'm not satisfied of the style of the textview in the multiple choice control, so I have to use the following code to create a new layout of a multiple choice control. It works well, but I don't think it's a good way, is there any good code? Thanks!
adapter = new SimpleCursorAdapter(this, R.layout.mysimple_list_item_multiple_choice, cur, cols, views);
lv.setAdapter(adapter);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mysimple_list_item_multiple_choice.xml
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:ellipsize="end"
android:singleLine="true"
/>
You need to extend BaseAdapter to create a custom Adapter.With A custom adapter each row of listview uses a xml layout and hence you can create a custom layout for rows .
Example code of custom adapter :
Setting adapter:
Links of examples:
example 1 example 2
R.layout.list_view_item is the custom xml for your list view ,in which you can add desired views .
Simple.
Use
<include>
.Create a new XML layout.
You can override all the layout parameters (any
android:layout_*
attributes) of the included layout's root view by specifying them in the tag.