开发者

custom views not updating with OnGroupClickListener on ExpandableListView

I have custom groupViews that need to change state when they are expanded and collapsed. If the same group view is expanded it toggles between two states.

The problem i'm having is that the expand method seems to be pulling up some cached version of the views because my updates aren't visible after calling expandGroup.

If my listener returns true (handles the whole event itself) without calling expandGroup the update does happen. So something is happening with expandGroup that only allows cached view to be drawn. I have tried invalidating() just about everything. I've tried firing off data update events on the List View. i've tried all this other stuff as well:

expandableList.setGroupIndicator(null);
        expandableList.setAlwaysDrawnWithCacheEnabled(false);
        expandableList.setWillNotCacheDrawing(true);
        expandableList.setItemsCanFocus(false);

no luck on any of those :(

Here's my onClick code:

expandableList.setOnGroupClickListener(new OnGroupClickListener() {

            public boolean onGroupClick(ExpandableListView parent, View v,
                    int groupPosition, long id) {
                MusicTrackRow mt = (MusicTrackRow) v;

                if (mt.isPla开发者_C百科ying == true) {
                    mt.setPaused();
                } else {
                    mt.setPlaying();
                }
                mt.invalidate();
                parent.invalidate();
                trackAdapter.notifyDataSetInvalidated();
//need to call expandGroup if the listener returns true.. if returning false expandGroup is //returned automatically
                                expandableList.expandGroup(groupPosition); //no view refresh
                    return true;


Found a solution finally!

When the expandable list is expanded a call to getGroupview in the adapter is made for every group on the list. That is the place where you want to effect changes. the isExpanded argument lets you determine which group view is expanded.

Then you can do stuff that looks like this:

public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        View v;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) getBaseContext()
                    .getSystemService(LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.expandablelistitem, null);

        } else {
            v = convertView;
        }
        int id = (!isExpanded) ? R.drawable.list_plus_selector
                : R.drawable.list_minus_selector;

        TextView textView = (TextView) v.findViewById(R.id.list_item_text);
        textView.setText(getGroup(groupPosition).toString());

        ImageView icon = (ImageView) v.findViewById(R.id.list_item_icon);

        icon.setImageResource(id);
        return v;

    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜