In my CheckActivity, when I checked checkBoxListAll, recyclerview list checked all. And when I check list one by one and finally list check all, set checkBoxListAll to check.
CheckActivity
...
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d("CheckMessage","boolean value " + isChecked);
if (isChecked){
checkAdapter.selectAll();
}else{
checkAdapter.selectNothing();
}
}
@Override
public void onMethodCallback(boolean checkAll) {
if (checkAll){
checkBoxListAll.setChecked(true);
}else{
checkBoxListAll.setChecked(false);
}
}
CheckAdapter
...
public CheckAdapter(Context context) {
super(context);
this.context = context;
try{
this.checkAdapterCallBack = ((CheckAdapterCallBack)context);
}catch (Exception e){
e.printStackTrace();
}
}
public void selectAll(){
isSelectAll = true;
for (int i = 0; i < checkItems.size(); ++i){
CheckData checkData = checkItems.get(i);
selectedList.put(i,checkData);
}
notifyDataSetChanged();
}
public void selectNothing(){
isSelectAll = false;
selectedList.clear();
notifyDataSetChanged();
}
public CheckAdapter(Context context) {
super(context);
this.context = context;
try{
this.checkAdapterCallBack = ((CheckAdapterCallBack)context);
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onBindViewHolder(final CheckItemViewHolder holder, final int position) {
super.onBindViewHolder(holder, position);
if (selectedList.size() == checkItems.size()){
try{
checkAdapterCallBack.onMethodCallback(true);
}catch (Exception e){
}
}else{
try{
checkAdapterCallBack.onMethodCallback(false);
}catch (Exception e){
}
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
...
notifyItemChanged(position);
}
});
}
I check checkBoxAll, recyclerview's all list selected. And I unselect one in recyclerview when I check checkBoxAll, it release checkBoxAll.
CheckBoxAll -> checkListAll in Recyclerview(o) CheckBoxAll release -> checkList no one selected in Recyclerview(o)
If you see in CheckAdapter, select all the list in recyclerview, call checkAdapterCallBack's onMethodCallback and setChecked checkBoxListAll in CheckActivity.
After that, onCheckedChangedListener doesn't work.
I check and uncheck repeat, but it does not response.
Is there any problem that check checkBox from adapter?
I don't know why it is occurs.
If you know about it, please help me.
Aucun commentaire:
Enregistrer un commentaire