无法更新自定义适配器中的项目
Cant update item in custom adapter
我正在尝试为列表视图中的每个项目添加触摸监听器。
这是我在 CustomAdapter 中用于 currentView 的代码(我认为)
rowView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
return true;
case MotionEvent.ACTION_UP:
x2 = event.getX();
float deltaX = x2 - x1;
if (Math.abs(deltaX) > MIN_DISTANCE) {
if (x2 > x1) {
LEFT = false;
Logger.e("FALSE ");
txtTitle.setText("LEFT TO RIGHT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
HomeChatAdapter.super.notifyDataSetChanged();
}
else {
LEFT = true;
Logger.e("TRUE");
txtTitle.setText("RIGHT TO LEFT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
}
} else {
CLICKITEM = true;
return false;
}
break;
}
return false;
}
});
动画和 view.setText("blabla") 有问题
当我滑动完成时 "from left to right or from right to left"
屏幕上没有变化
如果我搬出去
txtTitle.setText("LEFT TO RIGHT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
这部分代码来自 TouchListener - 一切正常,但它在创建时工作了一次。
任何人都可以帮助我在这种情况下如何解决?
只想将列表视图中的项目向左或向右移动。关注彼得。
如果我没有正确理解你的问题,你想使用
swipeLayout.startAnimation(...);
相反。
根据setAnimation vs startAnimation in android:
setAnimation
Sets the next animation to play for this view.But view animation does
not start yet.
startAnimation
If you want the animation to play immediately, use startAnimation.
This method provides allows fine-grained control over the start time
and invalidation, but you must make sure that
1) the animation has a start time set,
2) the view will be invalidated when the animation is supposed to
start.
我正在尝试为列表视图中的每个项目添加触摸监听器。 这是我在 CustomAdapter 中用于 currentView 的代码(我认为)
rowView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
return true;
case MotionEvent.ACTION_UP:
x2 = event.getX();
float deltaX = x2 - x1;
if (Math.abs(deltaX) > MIN_DISTANCE) {
if (x2 > x1) {
LEFT = false;
Logger.e("FALSE ");
txtTitle.setText("LEFT TO RIGHT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
HomeChatAdapter.super.notifyDataSetChanged();
}
else {
LEFT = true;
Logger.e("TRUE");
txtTitle.setText("RIGHT TO LEFT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
}
} else {
CLICKITEM = true;
return false;
}
break;
}
return false;
}
});
动画和 view.setText("blabla") 有问题 当我滑动完成时 "from left to right or from right to left" 屏幕上没有变化 如果我搬出去 txtTitle.setText("LEFT TO RIGHT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
这部分代码来自 TouchListener - 一切正常,但它在创建时工作了一次。 任何人都可以帮助我在这种情况下如何解决? 只想将列表视图中的项目向左或向右移动。关注彼得。
如果我没有正确理解你的问题,你想使用
swipeLayout.startAnimation(...);
相反。
根据setAnimation vs startAnimation in android:
setAnimation
Sets the next animation to play for this view.But view animation does not start yet.
startAnimation
If you want the animation to play immediately, use startAnimation. This method provides allows fine-grained control over the start time and invalidation, but you must make sure that
1) the animation has a start time set,
2) the view will be invalidated when the animation is supposed to start.