How to start animation when I'm pressing on item of ListView?
Posted
by
Ares
on Stack Overflow
See other posts from Stack Overflow
or by Ares
Published on 2012-09-04T03:35:19Z
Indexed on
2012/09/04
3:37 UTC
Read the original article
Hit count: 232
android
|android-gesture
I want to implement next functional: When I'm tapping on ListView's item, it's turning into red color. If I release it has to reverse color back. I made transition drawable and set it as item's background. I tried to implement SimpleGestureListener
and started animation on onDown
and reversed it on onSingleTapUp
events, but it doesn't give me any results (works fine, but items don't turn into red). If I return super.onDown
(not true), the onLongPress raise every time(even I manage to release it).
@Override
public boolean onDown(MotionEvent e) {
if(_currentRow.getTag()!=null)
if(_currentRow.getTag().toString().equals("anim"))
_currentRow.setBackgroundDrawable(context.getResources()
.getDrawable(R.xml.listviewitem_yellow_red));
_drawable = (TransitionDrawable) _currentRow.getBackground();
_drawable.startTransition(500);
return true;
//super.onDown(e); // IF I UNCOMMENT IT TURNS INTO RED, BUT TRIGGERED onLongClick event!!!
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
if(_drawable!=null){
_drawable.reverseTransition(500);
}
return super.onSingleTapUp(e);
}
@Override
public void onLongPress(MotionEvent e) {
if(getLongClickListener()!=null)
getLongClickListener().onLongClick(_currentRow, _object);
super.onLongPress(e);
}
If someone knows how to solve this problem, please help me.
© Stack Overflow or respective owner