jeudi 1 septembre 2016

Checked All Child Issue

Actually I am Not getting size when i am printing Toast in checkedbox Checked Event in android.

Here is my Code on parent checkbox in android if i will get the size the problem will automatically solved.

This code is declared in custom Adapter.

public void onBindViewHolder(final MyViewHolder holder, int position) {
    //Toast.makeText(context, "Key: " + position, Toast.LENGTH_LONG).show();
    String val = allCityList.get(position);
    Integer cnt = val.split("-").length;

    if (cnt > 1) {
        val = val.split("-")[1];
        holder.chkbox_parent.setText(val);
        holder.chkbox_parent.setTag("State");
        holder.chkbox_parent.setTypeface(null, Typeface.BOLD);

        stateTag = val;
    } else {
        val = val.split("-")[0];
        holder.chkbox_parent.setText(val);
        holder.chkbox_parent.setTag(stateTag);
    }

holder.chkbox_parent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            CheckBox chk = (CheckBox) holder.chkbox_parent;

            if (chk.getTag().equals("State")) {
                String state = chk.getText().toString();
                Toast.makeText(context, state, Toast.LENGTH_LONG).show();
                try {
                    RecyclerView rv1 = holder.rvParent;
//                        Toast.makeText(context, ""+rv1.getTag(), Toast.LENGTH_LONG).show();
                    for (int i = 0; i < rv1.getChildCount(); i++) {
                        Log.e("hello......", ""+rv1.getChildCount());
                        CheckBox cb;
                        cb = (CheckBox) rv1.getChildAt(i).findViewById(R.id.chkbox_parent);
                        Toast.makeText(context, "" + cb.getText(), Toast.LENGTH_LONG).show();
 //                if (state.equals(cb.getTag()))
//                    cb.setChecked(chk.isChecked());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

Issue is coming on recyclerview ie rv.getchildcount




Aucun commentaire:

Enregistrer un commentaire