使用幻灯片删除项目列表视图 - 就像 Gmail [英] Remove item listview with Slide - Like Gmail
问题描述
我正在开发一个带有列表视图中的商店列表的应用程序.我需要当我向右(或向左)滑动 listview
的项目时,这个项目应该从列表视图中删除.
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
.这是我的工作代码.
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) {
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()
- 分别向右滑动.在此功能中,您需要粘贴动画代码.
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.
这篇关于使用幻灯片删除项目列表视图 - 就像 Gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!