Android 子图像更改的可扩展列表视图,所有其他子图像默认在小屏幕中更改

问题描述

enter image description here

代码如下

请查看添加的适配器类。三张图片代码相同,我添加了一张的代码作为示例。

另请参阅上图。

问题是当我选择第一个子图像时,它也会自动选择第二个父第二个子图像

感谢您的帮助。

public Customexpandablelistadapter(Context context,List<String> expandableListTitle,HashMap<String,List<SafetyLineBean>> expandableListDetail,List<SafetyLineBean> safetyLineBeans,Activity activity) {
    this.context = context;
    this.expandableListTitle = expandableListTitle;
    this.expandableListDetail = expandableListDetail;
    this.safetyLineBeans = safetyLineBeans;
    this.activity = activity;
}

@Override
public Object getChild(int listPosition,int expandedListPosition) {
    return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).get(expandedListPosition);
}

@Override
public long getChildId(int listPosition,int expandedListPosition) {
    return expandedListPosition;
}

@Override
public View getChildView(int listPosition,final int expandedListPosition,boolean isLastChild,View convertView,ViewGroup parent) {
    final SafetyLineBean safetyLineBean = (SafetyLineBean) getChild(listPosition,expandedListPosition);
    if (convertView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.child_group,null);
    }

    TextView expandedListTextView = convertView.findViewById(R.id.expandedListItem);
    ImageView ivCheck = convertView.findViewById(R.id.iv_tick);
    ImageView ivBan = convertView.findViewById(R.id.iv_block);
    ImageView ivTimes = convertView.findViewById(R.id.iv_cross);

    /*for tick*/
    ivCheck.setonClickListener(v -> {
        if (safetyLineBean.isTickChecked) {
            ((CreateSafetyCheckActivity) activity).createSafetyLinesJSON(safetyLineBean.id,false,false);
            safetyLineBean.isTickChecked = false;
            ivCheck.setBackgroundDrawable(context.getDrawable(R.drawable.unchecked_tick));
        } else {
            ((CreateSafetyCheckActivity) activity).createSafetyLinesJSON(safetyLineBean.id,true,false);
            safetyLineBean.isTickChecked = true;
            safetyLineBean.isBanChecked = false;
            safetyLineBean.isTimesChecked = false;
            ivTimes.setBackgroundDrawable(context.getDrawable(R.drawable.unchecked_cross));
            ivBan.setBackgroundDrawable(context.getDrawable(R.drawable.unchecked_safety_icon_3));
            ivCheck.setBackgroundDrawable(context.getDrawable(R.drawable.checked_tick));
        }
    });

   
    ivBan.setTag(expandedListPosition);
    ivTimes.setTag(expandedListPosition);
    ivCheck.setTag(expandedListPosition);
    expandedListTextView.setText(safetyLineBean.description);
    return convertView;
}

@Override
public int getChildrenCount(int listPosition) {
    return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).size();
}

@Override
public Object getGroup(int listPosition) {
    return this.expandableListTitle.get(listPosition);
}

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

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

@Override
public View getGroupView(int listPosition,boolean isExpanded,ViewGroup parent) {
    String listTitle = (String) getGroup(listPosition);
    if (convertView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.parent_group,null);
    }
    TextView listTitleTextView = convertView.findViewById(R.id.listTitle);
    listTitleTextView.setTypeface(null,Typeface.BOLD);
    listTitleTextView.setText(listTitle);
    return convertView;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...