标签:listview
ListView自身带了单选、多选模式,可通过listview.setChoiceMode来设置:listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);//开启多选模式listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);//开启单选模式listview.setChoiceMode(ListView.CHOICE_MODE_NONE);//默认模式listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);//没用过,不知道用来干嘛的
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/c1" android:state_pressed="true"/> <item android:drawable="@color/c1" android:state_checked="true"/> <item android:drawable="@color/c2"/> </selector>但是单选选中时的颜色还是系统选中的颜色,而不是自己设定的c1,不知道为什么?
public class CheckableLinearLayout extends LinearLayout implements Checkable { private boolean mChecked; public CheckableLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void setChecked(boolean checked) { mChecked = checked; setBackgroundDrawable(checked ? new ColorDrawable(0xff0000a0) : null);//当选中时呈现蓝色 } @Override public boolean isChecked() { return mChecked; } @Override public void toggle() { setChecked(!mChecked); } }
<com.ljfbest.temp.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:textAppearance="?android:attr/textAppearanceListItemSmall" /> </com.ljfbest.temp.CheckableLinearLayout>
ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects.This is intended as a base class; you will probably not need to use this class directly in your own code.
标签:listview
原文地址:http://blog.csdn.net/ljfbest/article/details/40685327