我的列表视图中有一些行,每行在列表单击事件上有两个不同的图像。当我单击列表视图时,我想要更改该列表视图的图像。单击鼠标时图像会发生变化。但是一旦点击被释放,图像就会消失。即使点击发布,我也希望它能够持续存在。
以下是我使用的代码。
public void onItemClick(AdapterView<?> p, View view, int position,
long id) {
listViewpos = position;
listViewName = hospitalList.get(position).HospName;
selectedHosp = WSParser.hospitalInfo.get(position);
hospitalID = selectedHosp.HospID;
Log.d("onCreate", "hospitalID " + hospitalID);
vwSubParent = (RelativeLayout) view.findViewById(R.id.relativeLayout1);
vwChildLay = (LinearLayout) vwSubParent.findViewById(R.id.linearLayout2);
imgSelected = (ImageView) vwChildLay.findViewById(R.id.imageView1);
imgSelected.setBackgroundResource(R.drawable.listviewselectorimage);
}
listviewselectorimage.xml如下所示
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use selected mark -->
<item android:drawable="@drawable/selectedmark"
android:state_pressed="true" />
<!-- When not selected, use selectedmark_black-->
<item android:drawable="@drawable/selectedmark_black" />
</selector>
});