自定义视图不OnGroupClickListener上ExpandableListView更新 [英] custom views not updating with OnGroupClickListener on ExpandableListView

查看:132
本文介绍了自定义视图不OnGroupClickListener上ExpandableListView更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要改变的状态,当他们展开和折叠定制groupViews。
如果同一组视图中展开它切换两种状态之间。

我遇到的问题是,扩大方法似乎是因为我更新不调用expandGroup后可见被拉起的意见,一些缓存的版本。

如果我的监听器返回true(处理整个事件本身),而不调用expandGroup更新确实会发生。因此,一些与expandGroup只允许要被绘制缓存视图发生。
我曾尝试无效化(),一应俱全。我试过发射过的列表视图数据更新的事件。我已经尝试了所有这其他的东西,以及:

  expandableList.setGroupIndicator(NULL);
        expandableList.setAlwaysDrawnWithCacheEnabled(假);
        expandableList.setWillNotCacheDrawing(真);
        expandableList.setItemsCanFocus(假);

这是任何那些没有运气:(

下面是我的onClick code:

  expandableList.setOnGroupClickListener(新OnGroupClickListener(){            公共布尔onGroupClick(ExpandableListView父视图V,
                    INT groupPosition,长ID){
                MusicTrackRow MT =(MusicTrackRow)V;                如果(mt.isPlaying ==真){
                    mt.setPaused();
                }其他{
                    mt.setPlaying();
                }
                mt.invalidate();
                parent.invalidate();
                trackAdapter.notifyDataSetInvalidated();
//需要调用expandGroup如果监听器返回true ..如果返回false expandGroup是//自动返回
                                expandableList.expandGroup(groupPosition); //没有视图刷新
                    返回true;


解决方案

找到一个解决办法终于来了!

在可扩展列表展开的适配器getGroupview呼吁名单上每个组而成。
这就是你想要改变效果的地方。
在isExpanded参数可以让你决定哪一组视图中展开。

然后,你可以做的东西,看起来像这样:

 公开查看getGroupView(INT groupPosition,布尔isExpanded,
            查看convertView,父母的ViewGroup){
        视图V;
        如果(convertView == NULL){
            LayoutInflater吹气=(LayoutInflater)getBaseContext()
                    .getSystemService(LAYOUT_INFLATER_SERVICE);
            V = inflater.inflate(R.layout.expandablelistitem,NULL);        }其他{
            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的图标=(ImageView的)v.findViewById(R.id.list_item_icon);        icon.setImageResource(ID);
        返回伏;    }

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.isPlaying == 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;

    }

这篇关于自定义视图不OnGroupClickListener上ExpandableListView更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆