5

I was playing with the new RecyclerView. and ran into a few issues:

  1. I noticed that it didnt support a click listener; I fixed that by adding a click listener to each list item. (RecyclerView onClick)
  2. When a list item is clicked, it doesnt show lolipop's nice clicking animation; I fixed that by adding the following attribute to the listitem XML: android:background="?android:attr/selectableItemBackground" (RecyclerView onItemClick effect in L)
  3. My actual problem: when I click a list item in the RecyclerView, the listener is notified immediately; I don't like this, because the user is not able to see the click animation complete before the click listener goes to the next activity or something.

How can I make the RecyclerView behave more like the ListView when being clicked such that the user is able to see the click animation complete before the click listener is notified?

I understand that I can simply fix this, by using View.postDelayed, but this doesn't seem like the best solution, because during the delay, the user may be able to click on more list items.

Below is a link to a repository of an android studio project that has a ListView and RecyclerView side by side to help demonstrate the issue: https://github.com/ericytsang/question.listview-vs-recyclerview

Thanks a lot!

Community
  • 1
  • 1
Eric
  • 12,320
  • 4
  • 53
  • 63

1 Answers1

1

I had the same issue. I was working with fragments and replacing the fragments when a list item is clicked, but the click animation doesn't show up. So, I replaced the fragment code with the code to start another Activity, and that solved my problem. You said the animation is not complete before the click listener goes to even another "activity or something", but for me works.

Insted of this

NewFragment newFragment = NewFragment.newInstance();
FragmentTransaction ft = (getFragmentManager()).beginTransaction();
ft.replace(R.id.fragment_container, newFragment);
ft.addToBackStack(null);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();

I use this

Intent transitionIntent = new Intent(getActivity(), DetailActivity.class);
startActivity(transitionIntent);
e3vela
  • 36
  • 1
  • 5
  • after experimenting a little, you're right! making the listener start another activity using an intent does solve the problem, and I can see the animation complete before the next activity starts. But, as you pointed out, for things like fragment transactions, and showing dialogs, you can't see the animation complete. oh well! – Eric Jul 28 '15 at 13:31
  • I will continue digging about this, there must be a reason for the animation not completing or a way to solve it using fragments. If there's anything new, I let you know. – e3vela Jul 29 '15 at 14:12