我需要在imageView上检测到OnClick事件,并获得从光标获取行的位置,我不知道如何。我正在尝试修改https://github.com/odoo-mobile/framework和购物车应用程序。
布局视图的代码需要检测到点击事件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="horizontal"
android:padding="10dp" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="7dip"
android:padding="2dip" >
<odoo.controls.BezelImageView
android:id="@+id/image_small"
android:layout_width="40dp"
android:layout_margin="@dimen/default_8dp"
app:maskDrawable="@drawable/circle_mask"
android:layout_height="40dp" />
</LinearLayout>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/thumbnail"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@color/body_text_1"/>
<LinearLayout
android:id="@+id/cart_plus_minus_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/name"
android:orientation="horizontal" >
<TextView
android:id="@+id/list_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginLeft="60dip"
android:layout_weight="0.23"
android:paddingRight="5dip"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@color/android_red" />
<ImageView
android:id="@+id/cart_minus_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_minuscircle" />
<TextView
android:id="@+id/cart_product_quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:text="0"
android:textSize="18dip"
android:textStyle="bold" />
<ImageView
android:id="@+id/cart_plus_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_addcircle" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
我需要检测到的图像是: @ id/cart_plus_img @ id/cart_minus_img
行时单击捕获事件的功能是:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ODataRow row = OCursorUtils.toDatarow((Cursor) mAdapter.getItem(position));
//AddToCart(row);
loadActivity(row);
}
当用户单击行时,我需要调用loadActivity(row(,但是当单击 @ id/cart_plus_img @ id/cart_minus_img调用另一个函数,但使用行参数
任何帮助是感谢
使用视图的标签属性
ImageView imgMinus = (ImageView)view.findViewById(R.id.cart_minus_img);
ImageView imgPlus = (ImageView)view.findViewById(R.id.cart_plus_img);
imgMinus.setTag(position);
imgPlus.setTag(position);
imgMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer position = (Integer) v.getTag();
...
}
});
imgPlus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer position = (Integer) v.getTag();
...
}
});