我有一个名为AmazingListView的ListView,我为这个ListView分配了一个选择器。例如,在Android 4.1.2中没有问题,但在Android 2.3.6中,当我点击某个项目时,所有项目都显示为已点击。在单击事件和指定方法的调用中,没有问题。我认为这来自选择器。我正在下面列出我的列表视图和选择器,感谢任何帮助:
<com.foound.widget.AmazingListView
android:id="@+id/amazing_lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:listSelector="@drawable/list_selector_menu_list_view"
android:cacheColorHint="@android:color/transparent"
android:choiceMode="singleChoice"/>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/fff42f2d"/>
</selector>
这是选择器中指定的颜色:
<color name="fff42f2d">#fff42f2d</color>
也许可能需要这个“getAmazingView”方法:
@Override
public View getAmazingView(int position, View convertView, ViewGroup parent) {
View res = convertView;
if (res == null) res = activity.getLayoutInflater().inflate(R.layout.menu_item, null);
// set background of this item text view
Bitmap itemBmp = aUrl;
if (Build.VERSION.SDK_INT >= 16) {
res.setBackground(new BitmapDrawable(getResources(), itemBmp));
} else {
res.setBackgroundDrawable(new BitmapDrawable(getResources(), itemBmp));
}
TextView lName = (TextView) res.findViewById(R.id.lName);
TextView lYear = (TextView) res.findViewById(R.id.lYear);
Items composer = getItem(position);
lName.setText(composer.title);
lYear.setText(composer.summary);
return res;
}
未点击时: https://www.dropbox.com/s/iu3epknzutpa4jq/device-2014-02-21-175429.png
点击后: https://www.dropbox.com/s/xv9285pcb7wuzp9/device-2014-02-21-175449.png
何时
谢谢..