Here my view is like the Country and its states...Like India,America,China etc and there sub States like for India is Delhi,UP,Gujarat for America Is Like Washington DC,LA etc now issue is I am using Checkbox when India is selected its child should select automatically and When America is selected there states should checked automatically here prob is when I select India It select all to American State rather then India I had used Recyclerview for this purpose as i am new i dont have any clue to add Images here.Parent have no issue.But child do have.Here is my code
Parents value in custom Adapter :
public void onBindViewHolder(final MyViewHolder holder, final int position) {
dynamiclist1();
final Employee emp = list.get(position);
holder.tv.setText(emp.getName());
if (emp.getName() == "India") {
holder.chkbox_parent.setTag("India");
}
holder.rv.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(context);
holder.rv.setLayoutManager(llm);
holder.rv.setHasFixedSize(true);
holder.chkbox_parent.setTag(emp.getName());
if (emp.getName() == "India") {
cuChild = new CustomAdapter_child(context, child1, "India");
} else {
cuChild = new CustomAdapter_child(context, child1, "");
}
holder.rv.setAdapter(cuChild);
holder.chkbox_parent.setTag(emp.getName());
holder.chkbox_parent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Toast.makeText(context, "" + holder.chkbox_parent.getTag(), Toast.LENGTH_SHORT).show();
try {
RecyclerView rv1 = (RecyclerView) itemview.findViewById(R.id.rv2);
Toast.makeText(context, "" + rv1.getChildCount(), Toast.LENGTH_SHORT).show();
CheckBox cb;
TextView txt;
for (int i = 0; i < rv1.getChildCount(); i++) {
cb = (CheckBox) rv1.getChildAt(i).findViewById(R.id.chkbox_child);
//txt = (TextView) rv1.getChildAt(i).findViewById(R.id.tv2);
Toast.makeText(context, "" + cb.getText(), Toast.LENGTH_SHORT).show();
//if (holder.chkbox_parent.getTag() == cb.getTag()) {
cb.setChecked(holder.chkbox_parent.isChecked());
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Here is a child Adapter:
public void onBindViewHolder(MyViewHolder holder, int position) {
Employee_Child emp = list.get(position);
holder.tv.setText(emp.getName1().concat("-").concat(this.TAG ).concat(""+position));
if (this.TAG == "India") {
holder.chkchild.setText("India");
}
}
I had used recyclerview in Cardview i.e first recyclerview for Parent and cardview and recyclerview for its child In short I Had used nested Recyclerview.I had seen many examples but not got any single solution. Thank You in advance
Aucun commentaire:
Enregistrer un commentaire