AwaisMajeed
AwaisMajeed

Reputation: 2314

ExpandableListView items switch position when a group is expanded

I'm using ExpandableListView in fragment, everything works fine until I expand a group that has some selected value (i.e. in orange-ish color).enter image description here

Now after expanding a group, for example prayer reminder, it looks like thisenter image description here

Notice that items in red rectangles have switched places.

Here are my getGroupView() and getChildView() methods

@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;
    }

Upvotes: 1

Views: 516

Answers (1)

Iqbal Ahmad
Iqbal Ahmad

Reputation: 49

hi i had the same problem i fixed it by removing this condition if (convertView == null) from the getGroupView method

Upvotes: 1

Related Questions