Minimizing / expanding an extensible list view changes the random child switch in checkedtextview

I can implement checktextview in expandablelistview. But when I check for a specific child, the child of the other parent is also selected. I can’t understand why I have to deal with such a problem? Has anyone encountered a similar situation? Thank you for your help.

EDIT:

As I said, I created a logical multidimensional array in customadapter: `

Boolean[][] categoryx = new Boolean` [5][5];

The user adapter has a getchildView method:

 @Override
      public View getChildView(int groupPosition, final int childPosition,
          boolean isLastChild, View convertView, ViewGroup parent) {
          System.out.print(groupPosition);
          System.out.println(childPosition);
        final String children = (String) getChild(groupPosition, childPosition);
        CheckedTextView text = null;
        if (convertView == null) {
          convertView = inflater.inflate(R.layout.listrow_details, null);
        }
        text = (CheckedTextView) convertView.findViewById(R.id.detail_textView1);
        text.setText(children);

        convertView.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {

              ((CheckedTextView )v).toggle();
          }
        });
        return convertView;
      }

But I am confused by the fact that the method should switch my values ​​using the available child position.

EDIT 2: My custom adapter, where I am trying to save state:

import android.app.Activity;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;
import android.widget.Toast;

public class MyCategoryAdapter extends BaseExpandableListAdapter {

      private SparseArray<Groupx> groups;
      public LayoutInflater inflater;
      public Activity activity;
      Boolean[][] categoryx = new Boolean [5][5];

      public MyCategoryAdapter(Activity act, SparseArray<Groupx> groups) {
        activity = act;
        this.groups = groups;
        inflater = act.getLayoutInflater();
      }

      @Override
      public Object getChild(int groupPosition, int childPosition) {
        return groups.get(groupPosition).children.get(childPosition);
      }

      @Override
      public long getChildId(int groupPosition, int childPosition) {
        return 0;
      }

      @Override
      public View getChildView(int groupPosition, final int childPosition,
          boolean isLastChild, View convertView, ViewGroup parent) {
          System.out.print(groupPosition);
          System.out.println(childPosition);
        final String children = (String) getChild(groupPosition, childPosition);
        CheckedTextView text = null;
        if (convertView == null) {
          convertView = inflater.inflate(R.layout.listrow_details, null);
        }
        text = (CheckedTextView) convertView.findViewById(R.id.detail_textView1);
        text.setText(children);

        convertView.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              //Integer lol = (Integer) v.getTag();
              ((CheckedTextView )v).toggle();
          }
        });
        return convertView;
      }

      @Override
      public int getChildrenCount(int groupPosition) {
        return groups.get(groupPosition).children.size();
      }

      @Override
      public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
      }

      @Override
      public int getGroupCount() {
        return groups.size();
      }

      @Override
      public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
      }

      @Override
      public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
      }

      @Override
      public long getGroupId(int groupPosition) {
        return 0;
      }

      @Override
      public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if (convertView == null) {
          convertView = inflater.inflate(R.layout.listrow_group, null);
        }
        Groupx group = (Groupx) getGroup(groupPosition);
        ((CheckedTextView) convertView).setText(group.stringx.toString());
        ((CheckedTextView) convertView).setChecked(isExpanded);
        return convertView;
      }

      @Override
      public boolean hasStableIds() {
        return false;
      }

      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
      }
    } 
+3
source share
3

, - ListView.

, . ListView , , , , , , .

, ListView ListView.

+2

singlechoicemode: true xml.

0

BaseExpandableListAdapter

public int getChildType(int groupPosition, int childPosition) {
 //define a condition here to differentiate between your child views.
}

public int getChildTypeCount() {
 return 2; <-- this is the number of views for your child
}

, .

0
source

All Articles