ExpandableListView项目在展开组时切换位置

时间:2017-06-05 06:40:28

标签: android

我在片段中使用ExpandableListView,一切正常,直到我展开一个具有一些选定值的组(即橙色的颜色)。enter image description here

现在,在扩展群组之后,例如祷告提醒,它看起来像enter image description here

请注意,红色矩形中的项目已切换位置。

以下是我的getGroupView()getChildView()方法

@Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.prayer_settings_list_item, parent, false);
        }
        ((TextView) convertView.findViewById(R.id.setting_name_tv)).setText((String) getGroup(groupPosition));
        return convertView;
    }


@Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = layoutInflater.inflate(R.layout.azan_selection_item, parent, false);

                MontserratRegTextView azanVoiceMakkahTv = (MontserratRegTextView) convertView.findViewById(R.id.azan_voice_tv);
                final ImageView icPlayPause = (ImageView) convertView.findViewById(R.id.azan_play_ic);
                icPlayPause.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PrayerSettingsFragment.listener.onClick(childPosition, icPlayPause);
                    }
                });
                String azanVoice = (String) getChild(groupPosition, childPosition);
                azanVoiceMakkahTv.setText(azanVoice);


        return convertView;
    }

1 个答案:

答案 0 :(得分:0)

我有同样的问题我通过从getGroupView方法中删除此条件if (convertView == null)来修复它