我正在开发一个商店列表中列表视图的应用程序。我需要的,当我的列表视图
项目轻扫到右(或左),这个项目应该从列表视图中删除。
I am developing an application with a shop list in a listview. I need that when I swipe the item of listview
to the right(or left), this item should get deleted from the listview.
我有我的列表视图,只需要功能做到这一点。
I have my listview and only need the function to do it.
在此先感谢。
这是怎么实现这种效果。我们有一个ListView lvSimple,我们onTouchListener添加到我们的lvSimple。这是我的工作code。
This is how I realize this effect. We have a ListView lvSimple and we add onTouchListener to our lvSimple. This is my working code.
float historicX = Float.NaN, historicY = Float.NaN;
static final int DELTA = 50;
enum Direction {LEFT, RIGHT;}
...
ListView lvSimple = (ListView) findViewById(R.id.linLayout);
...
lvSimple.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event)
{
// TODO Auto-generated method stub
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
historicX = event.getX();
historicY = event.getY();
break;
case MotionEvent.ACTION_UP:
if (event.getX() - historicX < -DELTA)
{
FunctionDeleteRowWhenSlidingLeft();
return true;
}
else if (event.getX() - historicX > DELTA)
{
FunctionDeleteRowWhenSlidingRight();
return true;
} break;
default: return false;
}
return false;
}
});
其中函数FunctionDeleteRowWhenSlidingLeft()时,当我们滑动到左侧,FunctionDeleteRowWhenSlidingRight主叫 - 分别在右侧。在这个功能,你需要粘贴code动画。
where function FunctionDeleteRowWhenSlidingLeft() is calling when when we sliding to the left, FunctionDeleteRowWhenSlidingRight - to the right respectively. In this function you need paste code for animation.