Why does ExpandableListView change ChildView settings (Android)?

一曲冷凌霜 提交于 2019-12-23 15:12:15

问题


I have a question to using the ExpandableListView. In my case I have two group- and two child views while the child views consist of a RelativeLayout with several Buttons, TextViews etc. in it. When expanding the second group first for instance and making some changes to the view holders and expanding the first group afterwards the previously made changes are automatically applied to the child view of the first group as well, why is this happening?

I logged when the views are called:

// Fragment with ExpandableListView in it created, convertViews of group 0 and 1 are null

convertView == null, GroupView, groupPosition 0

convertView == null, GroupView, groupPosition 1

// expanded second group first, convertView of Child is null

getChildView: group position 1, child position 0 convertView == null, ChildView

// expanded first group after, convertView of Child is NOT null anymore

getChildView: group position 0, child position 0 convertView != null, ChildView

It seems like that it is taking the convertView of the child of the second group, does the Tag not recognize witch view to take maybe?

EDIT:

@Override
public View getChildView(final int groupPosition, final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {

    if (LOG)
        Log.d(TAG, "getChildView: group position " + groupPosition + ", child position " + childPosition);

    final ViewHolder viewHolder;
    if (convertView == null) {
        viewHolder = new ViewHolder();
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item_channel, null);

        if (LOG) Log.d(TAG, "convertView == null, ChildView");

        // add all the viewholders (...)
        viewHolder.connect = (ToggleButton) convertView.findViewById(R.id.connect_tog);
        viewHolder.channelOnOff = (Switch) convertView.findViewById(R.id.channel_switch);
        convertView.setTag(viewHolder);

    } else {
        if (LOG) Log.d(TAG, "convertView != null, ChildView");
        viewHolder = (ViewHolder) convertView.getTag();
    }

    return convertView;

}

No, I'm not changing the views by an adapter externally, also the ViewHolder class is a static class.

Thanks a lot and cheers, pingu

来源:https://stackoverflow.com/questions/30594599/why-does-expandablelistview-change-childview-settings-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!