Recyclerview Changing Items During Scroll

前端 未结 15 711
我在风中等你
我在风中等你 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:09

    This is the expected behaviour of recyclerView. Since the view is recycled your items may get into random views. To overcome this you have to specify which item is put into which kind of view by yourself. This information can be kept in a SparseBooleanArray. what you can do is create a SparseBooleanArray in your adapter like this

    SparseBooleanArray selectedItems = new SparseBooleanArray();
    

    whenever your view changes, do:

    selectedItems.put(viewItemIndex,true);
    

    Now in your onBindViewHolder do

     if(selectedItems.get(position, false)){
        //set progress bar of related to the view to desired position
        }
        else {
            //do the default
        }
    

    This is the basic to solve your problem. You can adjust this logic to any kind of similar problem in recyclerView.

提交回复
热议问题