Recyclerview Changing Items During Scroll

前端 未结 15 706
我在风中等你
我在风中等你 2020-11-27 10:38

I have a RecyclerView. Each row has a play button, textview and Progressbar. when click on the play button have to play audio from my sdcard and have to progress Progressbar

相关标签:
15条回答
  • 2020-11-27 11:10

    If your recyclerview ViewHolder has more logic or has a different different view then you should try:

     **order_recyclerView.setItemViewCacheSize(x);**
    

    where x is the size of the list. The above works for me, I hope it works for you too.

    0 讨论(0)
  • 2020-11-27 11:12

    I had the same problem while handle a lot of data , it works with 5 because it renders the five elements that are visible on the screen but that gives prob with more elements. The thing is ..

    Sometimes RecyclerView and listView just skips Populating Data. In case of RecyclerView binding function is skipped while scrolling but when you try and debug the recyclerView adapter it will work fine as it will call onBind every time , you can also see the official google developer's view The World of listView. Around 20 min -30 min they will explain that you can never assume the getView by position will be called every time.

    so, I will suggest to use

    RecyclerView DataBinder created by satorufujiwara.

    or

    RecyclerView MultipleViewTypes Binder created by yqritc.

    These are other Binders available if you find those easy to work around .

    This is the way to deal with MultipleView Types or if you are using large amount of data . These binders can help you just read the documentation carefully that will fix it, peace!!

    0 讨论(0)
  • 2020-11-27 11:12

    I had the similar issue and searched alot for the right answer. Basically it is more of a design of recycler view that it updates the view on the scroll because it refreshes the view.

    So all you need to do is at the bind time tell it not to refresh it.

    This is how your onBindViewHolder should look like

    @Override
    @SuppressWarnings("unchecked")
    public void onBindViewHolder(final BaseViewHolder holder, final int position) {
        holder.bind(mList.get(position));
    
        // This is the mighty fix of the issue i was having
        // where recycler view was updating the items on scroll.
        holder.setIsRecyclable(false);
    }
    
    0 讨论(0)
  • 2020-11-27 11:16

    Please try this

    1. If you are using ListView - override the following methods.

       @Override
       public int getViewTypeCount() {    
           return getCount();
       }
      
       @Override
       public int getItemViewType(int position) {    
           return position;
       }
      
    2. If you are using RecyclerView - override only getItemViewType() method.

       @Override
       public int getItemViewType(int position) {    
           return position;
       }
      
    0 讨论(0)
  • 2020-11-27 11:20

    Override the method getItemViewType in adapter. in kotlin use

    override fun getItemViewType(position: Int): Int {
        return position
    }
    
    0 讨论(0)
  • 2020-11-27 11:22

    I have faced the same problem while I was trying to implement a recyclerview that contains a edittex and a checkbox as a row elements. I solved the scrolling value changing problem just by adding the following two lines in the adapter class.

    @Override
    public long getItemId(int position) {
        return position;
    }
    
    @Override
    public int getItemViewType(int position) {
        return position;
    }
    

    I hope it will be a possible solution. Thanks

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