I'm displaying a checked recyclerview in my edit details screen of application. When I go to edit screen I'm able to get the previously selected items are marked as checked working fine, but my challenge is I'm not able to edit the previously selected items along with newly selected items. Only new selected items are updated in my server.

For ex: previuosly I selected {1,2} position items, when I go to edit screen 1,2 items are marked as checked, remaining as marked unchecked. Now if I select new items{3,4} only {3,4} added previously selected items{1,2} not added and sometimes they are not editable even.

Here is my viewholder class:

//in some cases, it will prevent unwanted situations

        //if true, your checkbox will be selected, else unselected

        for(int i=0;i<model.getTargetedMarketingOption().size();i++){

        holder.cell.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                boolean isChecked = !holder.checkBox.isChecked();
                guestListener.OnMultipleMarketOptListener(position, isChecked);

Here is selected items list get in my activity:

    public void OnMultipleMarketOptListener(int position, boolean isChecked) {


You should understand the sliding principle of recyclerView again, and then try to understand what I do below.

in you adapter:

hashMap<Int,Boolean> checkStatusMap,// int is position, Boolean is CheckStatus

in your listener class:

//Ensure that the current location is correct in recyclerView
int mPosition ;
void updateViewByPosition?int position?{
   checked= getCheckStatusByPosition(mPosition,checkStatusMap);

public void onClick(View v) {
   boolean newChecked= !getCheckStatusByPosition(mPosition,checkStatusMap);
   SaveCheckStatusByPosition(newChecked,mPosition,checkStatusMap);//You need a map or list to store state

in your onCreateViewHolder ???:

viewHolder.setOnClickListener(listener);//You need to implement a listener

Here is selected items list get in your onBindViewHolder:

public void onBindViewHolder(int position) {

Where you upload the network:

  • 1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions