im trying to add touchlistener for every item in listview. here my code in my CustomAdapter for currentView (as i think)
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;
}
});
problem with animation and view.setText("blabla") When my swipe is done "from left to right or from right to left" no changes on screen If i move out txtTitle.setText("LEFT TO RIGHT");
moveLefttoRight = new TranslateAnimation(0, -150, 0, 0);
moveLefttoRight.setDuration(1500);
moveLefttoRight.setFillAfter(true);
swipeLayout.setAnimation(moveLefttoRight);
this part of code from TouchListener - than all ok but its work one time when created. Can any help me how to do solution in this situation ? Just want to move item in listview to left or right . Regard Peter.
If I am understanding your question correctly, you want to use
swipeLayout.startAnimation(...);
instead.
According to 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.