我在我的布局中有一个ListView。这是列表项目的布局。Android问题相关OnItemClickListener的ListView
shopitem.xml
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:mode="twoLine">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="44dip"
android:textStyle="bold"
android:lines="1"
android:textColor="#FFFFFF"/>
<ImageView
android:id="@+id/playBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dip"
android:layout_alignRight="@android:id/text1"
android:src="@drawable/btnplaypreview"/>
</TwoLineListItem>
现在我想设置图像的一些变化playBtn
OnItemClickListener。为此,我使用下面的代码。
ListView shopActivityListView = (ListView) findViewById(R.id.shopActivityListView);
shopActivityListView.setCacheColorHint(Color.TRANSPARENT);
shopActivityListView.setAdapter(new ArrayAdapter<String>(getApplicationContext(), R.layout.shopitem, trackArr[1]));
shopActivityListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View vItem, int position, long id) {
// TODO Auto-generated method stub
ImageView playBtn = (ImageView) vItem.findViewById(R.id.playBtn);
playBtn.setImageResource(R.drawable.eq12);
}
});
但是没有发生在itemclick上。我检查了onItemClick
方法正在执行,没有任何异常。但没有什么改变。我的代码中有什么问题?
TwoLineListItem是一个linearlayout扩展吗?尝试添加'android:clickable =“true”' –
我试过了。不用找了。 –
playBtn.setImageResource(R.drawable.eq12);无效后,您的列表视图。 –