繁体   English   中英

android - 在expandableListView的子项上单击了什么按钮

[英]android - what button is clicked on expandableListView's child

你好everibody,谢谢你读了我。

我希望自己能正确表达,因为我是法国人...如果你不明白,请告诉我。

我有一个expandableListActivity,并且,使用适配器,我已经放了孩子。 每个孩子都有两个按钮,可以减少或增加一个数字(命名数量)。 我很难知道,当按下按钮时,孩子会关注什么。 请注意,按下按钮时,相关的孩子并不总是选中的孩子。

我已经看过这个页面http://www.geekmind.net/2009/11/android-custom-list-item-with-nested.html感谢Andikki在这个页面上的回答在expandablelistview中创建按钮我已经部分解决了问题。

实际上,标签的解决方案似乎解决了问题,但事实并非如此。 当我快速点击按钮时,我有一个错误。 所有工作,但如果我快速点击一个按钮,例如在最短的时间内20次,点击的按钮并不总是正确检测到。

在我的情况下,我想增加或减少孩子的数量“数量”。 当我点击加号按钮或减号按钮时,它可以正常工作。 但是,当我快速点击同一个按钮时,发生的数量增加或减少的数量不是好孩子的数量!

我把你的代码如下,如果你想要更多,请告诉我。 这是child_row

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView
    android:id="@+id/childname"
    android:textStyle="italic"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
android:gravity="center_vertical"
    android:maxWidth="150dip"
    android:singleLine="false"/>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical|right"
        android:gravity="center_vertical|right">

    <ImageView
        android:id="@+id/decrease_quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/minus"
        android:background="@color/transparent"
        android:clickable="true"
        android:onClick="decreaseQuantity"/>

    <TextView
            android:id="@+id/quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1"/>

    <ImageView
        android:id="@+id/increase_quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/plus"
        android:background="@color/transparent"
        android:clickable="true"
        android:onClick="increaseQuantity"/>

</LinearLayout>

</LinearLayout>

这是我的适配器中getChildView方法的摘录:

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

    View v = null;

    if (convertView != null){
        v = convertView;
    }
    else{
        v = inflater.inflate(R.layout.child_row, parent, false); 
    }

    Product product = (Product)getChild(groupPosition,childPosition);

    ImageView decreaseQuantityImageView = (ImageView)v.findViewById(R.id.decrease_quantity);
decreaseQuantityImageView.setTag(groupPosition + "/" + childPosition);

TextView quantity = (TextView)v.findViewById(R.id.quantity);
quantity.setText(String.valueOf(product.getQuantity()));

ImageView increaseQuantityImageView = (ImageView)v.findViewById(R.id.increase_quantity);
increaseQuantityImageView.setTag(groupPosition + "/" + childPosition);

// I do that for all ImageView clickable of child   

return v;

}

这里是我的活动的摘录(扩展ExpandableListActivity)与getTag()

public void increaseQuantity(View v){

    ImageView increaseQuantityImageView = (ImageView)v.findViewById(R.id.increase_quantity);
    String positions = (String) increaseQuantityImageView.getTag();
    String tabOfPositions[] = positions.split("\\/");

    Product product = (Product)this.retailerAdapter.getChild(Integer.parseInt(tabOfPositions[0]), Integer.parseInt(tabOfPositions[1]));
    product.increaseQuantity();

    this.retailerAdapter.notifyDataSetChanged();

}

我不确定,但我认为我已经解决了这个问题。 目前,我不再看到这个错误了。

这是“解决方案”(如果有人可以解释我......)。

我删除了以下代码:

if (convertView != null){
    v = convertView;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM