Note that there are some explanatory texts on larger screens.

plurals
  1. POTouch animation and OnItemClick in AdapterView
    primarykey
    data
    text
    <p>I have a grid with items like this:</p> <p><a href="http://petromi.com/get/ba4a24f852.png" rel="nofollow noreferrer">http://petromi.com/get/ba4a24f852.png</a></p> <p>And I want to play animation for album cover when user touches it. I have created a class for this purpose:</p> <pre><code>class TouchAnimationHelper { ... public void setItemTouchAnimation(final View view) { view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); Log.d("Touch action: [%s]", action); if (action == MotionEvent.ACTION_DOWN) { view.startAnimation(sDecAnimation); return true; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { if (action == MotionEvent.ACTION_UP) { sIncAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { sIncAnimation.setAnimationListener(null); view.performClick(); } @Override public void onAnimationRepeat(Animation animation) { } }); } view.startAnimation(sIncAnimation); return true; } return false; } }); } } </code></pre> <p>In adapter's <code>getView</code> method I call:</p> <pre><code>mTouchAnimationHelper.setItemTouchAnimation(view.findViewById(R.id.album_cover)); </code></pre> <p>But the result is not completely what I want. Animation is working when touch. But Grid's <code>onItemClick</code> is not called. It is called only when tap on text below the image. How can I make it call?</p> <p>I've tried some solutions but they were not successfull:</p> <ol> <li><p>Always return false in <code>onTouch</code>. But in that case there are no other touch actions proceed, out animation is not playing.</p></li> <li><p>Pass additional parameters to <code>setItemTouchAnimation</code> and call <code>adapterView.performItemClick(view, position, id)</code> instead of <code>view.performClick()</code>. But in this case I got strange mess: raised event's item id didn't match clicked item id. I didn't still understand, why so.</p></li> </ol> <p>Any other ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload