RecyclerView vs. ListView

前端 未结 16 1735
名媛妹妹
名媛妹妹 2020-11-22 06:07

From android developer (Creating Lists and Cards):

The RecyclerView widget is a more advanced and flexible version of ListView.

<
相关标签:
16条回答
  • 2020-11-22 06:26

    Major advantage :

    ViewHolder is not available by default in ListView. We will be creating explicitly inside the getView(). RecyclerView has inbuilt Viewholder.

    0 讨论(0)
  • 2020-11-22 06:28

    In my opinion RecyclerView was made to address the problem with the recycle pattern used in listviews because it was making developer's life more difficult. All the other you could handle more or less. For instance I use the same adapter for ListView and GridView it doesn't matter in both views the getView, getItemCount, getTypeCount is used so it's the same. RecyclerView isn't needed if ListView with ListAdapter or GridView with grid adapters is already working for you. If you have implemented correctly the ViewHolder pattern in your listviews then you won't see any big improvement over RecycleView.

    0 讨论(0)
  • 2020-11-22 06:35
    1. You can use an interface to provide a click listener. I use this technique with ListViews, too.
    2. No divider: Simply add in your row a View with a width of match_parent and a height of 1dp and give it a background color.
    3. Simply use a StateList selector for the row background.
    4. addHeaderView can be avoided in ListViews, too: simply put the Header outside the View.

    So, if efficiency is your concern, then yes, it's a good idea to replace a ListView with a RecyclerView.

    0 讨论(0)
  • 2020-11-22 06:36

    I worked a little with RecyclerView and still prefer ListView.

    1. Sure, both of them use ViewHolders, so this is not an advantage.

    2. A RecyclerView is more difficult in coding.

    3. A RecyclerView doesn't contain a header and footer, so it's a minus.

    4. A ListView doesn't require to make a ViewHolder. In cases where you want to have a list with sections or subheaders it would be a good idea to make independent items (without a ViewHolder), it's easier and doesn't require separate classes.

    0 讨论(0)
提交回复
热议问题