Android的 - 被点击expandableListView的孩子什么键 [英] android - what button is clicked on expandableListView's child
问题描述
您好everibody和感谢阅读我的。
我希望我的前preSS正确自己,因为我是法国人......请告诉我,如果你不明白的地方。
我有一个expandableListActivity,并与一个适配器,我已经把孩子的就可以了。每个孩子都有两个按钮减少或增加一些(名为数量)。我的困难是要知道,当一个按钮pressed,什么孩子而言。请注意,当一个按钮pssed $ P $,关心孩子是不是总是选择孩子。
我已经看到了这个网页。的http:/ /www.geekmind.net/2009/11/android-custom-list-item-with-nested.html 感谢Andikki的这个网页的创建于expandablelistview 按钮和我已经部分地解决这个问题。
实际上,标签的溶液似乎要解决的问题,但它不。
我有一个错误,当我赶紧点击一个按钮。所有的工作,但如果我赶紧点击一个按钮,比如20次在最短的时间内,点击该按钮并不总是正确的检测出来。
在我而言,我whant增加或在孩子减少了一些量。当我上的加号按钮或减号按钮点击,它的工作原理。
但是,当我赶紧点击一个按钮一样,可以出现的数量增加或减少不是好孩子的数量!
我把你我的code如下,如果你想了解更多,请告诉我。
在这里,它的child_row
<?XML版本=1.0编码=UTF-8&GT?;< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT><的TextView
机器人:ID =@ + ID / childname
机器人:TEXTSTYLE =斜体
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:重力=center_vertical
安卓了maxWidth =150dip
机器人:单线=FALSE/><的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =center_vertical |权
机器人:重力=center_vertical |右> < ImageView的
机器人:ID =@ + ID / decrease_quantity
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/负
机器人:背景=@色/透明
机器人:可点击=真
安卓的onClick =decreaseQuantity/> <的TextView
机器人:ID =@ + ID /数量
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=1/> < ImageView的
机器人:ID =@ + ID / increase_quantity
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/加
机器人:背景=@色/透明
机器人:可点击=真
安卓的onClick =increaseQuantity/>< / LinearLayout中>< / LinearLayout中>
这是在我的适配器getChildView方法的摘录:
公开查看getChildView(INT groupPosition,诠释childPosition,布尔isLastChild,查看convertView,父母的ViewGroup){ 视图V = NULL; 如果(convertView!= NULL){
V = convertView;
}
其他{
V = inflater.inflate(R.layout.child_row,父母,假);
} 产品产品=(产品)getChild(groupPosition,childPosition); ImageView的decreaseQuantityImageView =(ImageView的)v.findViewById(R.id.decrease_quantity);
decreaseQuantityImageView.setTag(groupPosition +/+ childPosition);TextView的数量=(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);//我这样做对儿童的所有ImageView的点击返回伏;}
和我在这里的活动的提取物(扩展ExpandableListActivity)与getTag()
公共无效increaseQuantity(视图v){ ImageView的increaseQuantityImageView =(ImageView的)v.findViewById(R.id.increase_quantity);
字符串位置=(字符串)increaseQuantityImageView.getTag();
串tabOfPositions [] = positions.split(\\\\ /); 产品产品=(产品)this.retailerAdapter.getChild(的Integer.parseInt(tabOfPositions [0])的Integer.parseInt(tabOfPositions [1]));
product.increaseQuantity(); this.retailerAdapter.notifyDataSetChanged();}
我不知道,但我想我已经解决了这个问题。
目前,我没有看到这个bug了。
下面是解决方案(如果有人能解释我...)。
我已删除了以下code:
如果(convertView!= NULL){
V = convertView;
}
Hello everibody and thanks to read me.
I hope I will express correctly myself because i'm french... Please tell me if you don't understand something.
I have an expandableListActivity, and, with an adapter, I have put childs on it. Every child has two buttons which reduce or increased a number (named quantity). My difficulty is to know, when a button is pressed, what child is concerned. Please note that when a button is pressed, the child concerned is not always the child selected.
I have seen this page http://www.geekmind.net/2009/11/android-custom-list-item-with-nested.html thanks to the Andikki's answer on this page Creating buttons in expandablelistview and I have partially solve the problem.
Indeed, the tag's solution seem to solve the problem, but it not. I have a bug when I quickly click on a button. All work, but if i quickly click on a button, for example 20 times in a minimum of time, the button clicked is not always right detected.
In my case, i whant to increase or decrease a number "quantity" in a child. When i click on the plus button, or the minus button, it works. But when i quickly click on a same button, it happends that the quantity increased or decreased is not the quantity of the good child !
I put you my code as follow, if you want more, please tell me. Here it's the 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>
Here it's an extract of the getChildView method in my adapter :
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;
}
And here an extract of my activity (extends ExpandableListActivity) with the 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();
}
I'm not sure, but I think that I have solved the problem. For the moment, I don't see the bug anymore.
Here is the "solution" (if somebody can explain me...).
I have deleted the following code :
if (convertView != null){
v = convertView;
}
这篇关于Android的 - 被点击expandableListView的孩子什么键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!