我有一个列表视图,它应该在每个项目中包含一些数据(文本)和一个 ImageView。所以这就是我所做的,但看起来 ImageView 不可点击:
这是布局代码的一部分:
<RelativeLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:paddingBottom="5dp" >
<ImageView
android:id="@+id/searchIcone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:scaleType="center"
android:background="#c7c7c7"
android:layout_marginTop="60dp"
android:layout_marginRight="20dp"
android:clickable="true"
android:focusable="false"
android:src="@drawable/search" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:paddingBottom="5dp" >
<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="25dp"
android:onClick="searchVisiter"
android:textColor="#000" />
<TextView
android:id="@+id/CityCountry"
android:layout_below="@id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:textColor="#000" />
和我的 Java 代码:
final ListView lv1 = (ListView) findViewById(R.id.ListViewEvents);
lv1.setAdapter(new EventListViewAdapter(EventListActivity.this, records));
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
JsonObject response = (JsonObject)o;
ID = response.getString("ID");
// If the image is clicked (doesn't work)
final ImageView img1 = (ImageView) findViewById(R.id.searchIcone);
img1.setClickable(true);
img1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(EventListActivity.this, ZBarScannerActivity.class);
startActivity(intent);
}
});
// If the list item is clicked (works)
Intent intent = new Intent(EventListActivity.this, SearchActivity.class);
startActivity(intent);
}
});
请问,你对此有什么想法吗?
谢谢你。