0

我的布局中有一个ListView。为了在其中显示列表,我使用了以下代码。

ListView shopActivityListView = (ListView) findViewById(R.id.shopActivityListView);
shopActivityListView.setAdapter(new ArrayAdapter<String>(getApplicationContext(), R.layout.shopitem, R.id.text1,trackArr[1]));

这是xmlshopitem.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"> <!-- android:background="@drawable/homebg" -->
    <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/buyBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:paddingTop="3dip"
            android:layout_marginLeft="252dip"
            android:layout_alignRight="@android:id/text1"
            android:src="@drawable/btnbuy"/>            
</TwoLineListItem>

现在我想onClickListenerImageView每个项目上添加一个。我怎样才能添加它?

4

2 回答 2

0

您必须实现 ArrayAdapter 并将 onclicklistners 放入 GetView。这是自定义列表视图的链接:http: //www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

GetView 函数在实现的 ArrayAdapter 类下。

于 2011-08-24T10:01:10.880 回答
0

为 listView实现OnItemClickListener并设置它。使 ImageView 在 android xml 中可点击。

在方法onItemClick中检查 ImageView id,你应该很高兴..

于 2011-08-24T10:25:39.667 回答