2013年8月26日星期一

[Android] ExpandableListView an incredible problem! ! !

me first say that my project scenario: I have such a requirement, slide to the right ExpandableListView the Child, Child of dynamic display [Delete] button .
This is my Child node layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <TextView
        android:id="@+id/textChildTitle"
        android:text="No Data"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:paddingLeft="40dp"
        android:layout_gravity="left|center_vertical" />
    <TextView
        android:id="@+id/textChildMoney"
        android:text="No Data"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:paddingRight="10dp"
        android:gravity="right|center_vertical" />
    <Button
        android:id="@+id/btnDel"
        android:text="删除"
        android:textColor="@android:color/white"
        android:textSize="10dp"
        android:background="@drawable/btn_delete_x"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:layout_gravity="right|center_vertical"
        android:visibility="gone" />
</LinearLayout>

The first two are display data, and finally a Button is the delete button, the default is not displayed. When I was at the interface above the slide when the slide position to obtain the View, and then to get through findViewById Button, Button to display the status of the final set, the code is as follows:

//获取手指开始按屏幕的位置和最后抬起手指的位置
int pos1 = this.elv.pointToPosition((int)e1.getX(),(int)e1.getY());
int pos2 = this.elv.pointToPosition((int)e2.getX(),(int)e2.getY());

//先判断是否触发Child的delete事件
//如果起始位置【pos1】和结束位置【pos2】是在同一个【Child】并且这个【Child】的位置有效
//并且滑动距离大于100px,则触发Delete
if (pos1 > -1 && pos1 == pos2 && (e2.getX() - e1.getX() > 100) && (e2.getX() - e1.getX() < 200)){
        //获取当前Child的【Delete】按钮
Button btnDel = (Button)elv.getChildAt(pos1).findViewById(R.id.btnDel);
if (btnDel != null){
btnDel.setVisibility(View.VISIBLE);
btnDel.setText("删除"+ pos1);        //我将当前所在的位置【Pos1】写到按钮上面,方便调试
btnDel.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "POS:" + ((TextView)((View)v.getParent()).findViewById(R.id.textChildMoney)).getText(), Toast.LENGTH_SHORT).show();

}
});
Log.i("BTN Show","SHOW:" + pos1);
//btnDel.setfo
return true;
}
}

then debug emulator above, the following are debugging steps:
1, which is just to run the program when the state [as shown below]:

2, I start the second set, and in the first slide trigger Delete Child above results as shown []:

As shown above, the button is displayed successfully, and the back shows the [Pos] current location, but I do not understand: why the current position of two?
3, above me in the second group, the second slide [Child above effect is as follows]:

here is normal, position 3 .
4, then, is where the title appeared, I clicked the first group, the first group is expanded, the emergence of a bizarre phenomenon:

shown: second group of second Child button in the display to the first group of a Child above, why is there such a problem?

please help out, here I have studied for a long time, after all, I do not know how it is, first thank you!
------ Solution ------------------------------------ --------
pointToPosition is AbsListView interface obtained is pure location, rather than the first of several groups of several, if you want ExpandableListView using estimated also getExpandableListPosition and getPackedPositionGroup, getPackedPositionChild used in conjunction with job.

second question, estimates and adapter in getChildView realization about, is not there like if (convertView == null) else like this, you look at the code for the button check processing is not and not only set the display settings hidden
------ reference --------------------------------- ------

For the second question, I really was just a show, not hidden, but I show the current clicked Child of Button, even though I did not hide it, but it should not be another group went off to! This is something I'm confused!
------ reference --------------------------------------- < br> My understanding is that you go through if (convertView == null) ... else ... to create a child view, could the system when calling getChildView originally belong to the second group of the second a first group of the View assigned first, the second and the second group of a re-created, resulting in a phenomenon
------ reference --------- ------------------------------
how not solve the second problem?
------ reference --------------------------------------- < br> demo landlord seeking to learn ah, I also encountered the same interface requirements, the delete button issues sliding kfcve123@163.com
------ reference ------------ ---------------------------
landlord, hello, can ask my ontouch events see hear MotionEvent. ACTION_MOVE. Can not slide, ask if they can give to help it?
------ reference --------------------------------------- < br>
I ask you to complete, and I have the same needs, can help me do
------ reference ---------------- -----------------------

I ask you to complete, and I have the same needs, the ability to do a favor  
Custom months ExpandListView inherited from the parent class, and then rewrite the two interfaces implement this interface in the activity

没有评论:

发表评论