80,349
社区成员
发帖
与我相关
我的任务
分享
<?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>
//获取手指开始按屏幕的位置和最后抬起手指的位置
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;
}
}