When i check item from recyclerview one i can add item in recyclerview second which is on same activity. When i delete item from second recyclerview through image i want to clear selected checkbox as unselected in recyclerview first one.In Advance Thanks!!
ListdataAdapter.java
@Override
public void onBindViewHolder(ListdataAdapter.MyViewHolder holder, final int position) {
final ListModel model = listData.get(position);
holder.tvNumber.setText(model.getId());
holder.tvName.setText(model.getName());
holder.cbAction.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(isChecked){
addcheckvalue.add(new CheckedValueModel(model.getId(),model.getName()));
itemCheckListner.onClicked(addcheckvalue);
}else{
Toast.makeText(context,"Item Click", Toast.LENGTH_SHORT).show();
}
});
}
CheckedListAdapter
@Override
public void onBindViewHolder(CheckedListAdapter.MyViewHolder holder, final int position) {
final CheckedValueModel model = checkedList.get(position);
holder.tvNumber.setText(model.getId());
holder.tvName.setText(model.getName());
holder.crossImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckedValueModel item = checkedList.get(position);
checkedList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position,checkedList.size());
Toast.makeText(context,"Removed : " + item, Toast.LENGTH_SHORT).show();
}
});
}
interface ItemCheckListner
public interface ItemCheckListner{
void onClicked(List<CheckedValueModel>list);
}
MainActivity
public class MainActivity extends Activity implements ItemCheckListner {
RecyclerView rvDataList;
ListdataAdapter listdataAdapter;
RecyclerView.LayoutManager layoutManager;
List<ListModel> dataList;
ArrayList<CheckedValueModel> checkedList;
RecyclerView rvCheckedList;
CheckedListAdapter checkedListAdapter;
CheckedValueModel checkedValueModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dataList = new ArrayList<>();
checkedList = new ArrayList<>();
rvDataList = findViewById(R.id.rvDataList);
rvCheckedList = findViewById(R.id.rvCheckedList);
listdataAdapter = new ListdataAdapter(dataList, this, this::onClicked);
layoutManager = new LinearLayoutManager(this);
rvDataList.setLayoutManager(layoutManager);
rvDataList.setAdapter(listdataAdapter);
listdataAdapter.notifyDataSetChanged();
datalist();
Log.d("checklist_size", "" + checkedList.size());
// checkedList.add(checkedValueModel);
checkedListAdapter = new CheckedListAdapter(checkedList, this);
layoutManager = new LinearLayoutManager(this);
rvCheckedList.setLayoutManager(layoutManager);
rvCheckedList.setAdapter(checkedListAdapter);
checkedListAdapter.notifyDataSetChanged();
}
private void datalist() {
dataList.add(new ListModel("1", "Piyush"));
dataList.add(new ListModel("2", "Raj"));
dataList.add(new ListModel("3", "Ravi"));
dataList.add(new ListModel("4", "Kapil"));
}
@Override
public void onClicked(List<CheckedValueModel>list) {
checkedList=(ArrayList<CheckedValueModel>)list;
checkedListAdapter.updateData(checkedList);
//Toast.makeText(this, data.getId() + data.getName(), Toast.LENGTH_SHORT).show();
}
}
****CheckedValueModel && ListModel ****
**
Both model are same.
**
public class CheckedValueModel {
String id;
String name;
public CheckedValueModel(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Aucun commentaire:
Enregistrer un commentaire