梁君 2015-12-09 09:21 采纳率: 0%
浏览 680

SlideExpandableListView适配器改变时,未通知到Activity

The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131230834, class com.wlyc.warehousechampions.ui.views.slideexpandable.ActionSlideExpandableListView) with Adapter(class com.wlyc.warehousechampions.ui.views.slideexpandable.SlideExpandableListAdapter)]

package com.wlyc.warehousechampions.ui.views.slideexpandable;

import com.wlyc.warehousechampions.R;

import android.view.View;
import android.widget.ListAdapter;

/**

  • ListAdapter that adds sliding functionality to a list.
  • Uses R.id.expandalbe_toggle_button and R.id.expandable id's if no
  • ids are given in the contructor. *
  • @author tjerk
  • @date 6/13/12 8:04 AM
    */
    public class SlideExpandableListAdapter extends AbstractSlideExpandableListAdapter {
    private int toggle_button_id;
    private int expandable_view_id;

    public SlideExpandableListAdapter(ListAdapter wrapped, int toggle_button_id, int expandable_view_id) {
    super(wrapped);
    this.toggle_button_id = toggle_button_id;
    this.expandable_view_id = expandable_view_id;
    }

    public SlideExpandableListAdapter(ListAdapter wrapped) {
    this(wrapped, R.id.expandable_toggle_button, R.id.expandable);
    }

    @Override
    public View getExpandToggleButton(View parent) {
    return parent.findViewById(toggle_button_id);
    }

    @Override
    public View getExpandableView(View parent) {
    return parent.findViewById(expandable_view_id);
    }
    }

package com.wlyc.warehousechampions.ui.views.slideexpandable;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;

/**

  • A more specific expandable listview in which the expandable area
  • consist of some buttons which are context actions for the item itself. *
  • It handles event binding for those buttons and allow for adding
  • a listener that will be invoked if one of those buttons are pressed. *
  • @author tjerk
  • @date 6/26/12 7:01 PM
    */
    public class ActionSlideExpandableListView extends SlideExpandableListView {
    private OnActionClickListener listener;
    private int[] buttonIds = null;

    public ActionSlideExpandableListView(Context context) {
    super(context);
    }

    public ActionSlideExpandableListView(Context context, AttributeSet attrs) {
    super(context, attrs);
    }

    public ActionSlideExpandableListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    }

    public void setItemActionListener(OnActionClickListener listener, int ... buttonIds) {
    this.listener = listener;
    this.buttonIds = buttonIds;
    }

    /**

    • Interface for callback to be invoked whenever an action is clicked in
    • the expandle area of the list item. / public interface OnActionClickListener { /*
      • Called when an action item is clicked. *
      • @param itemView the view of the list item
      • @param clickedView the view clicked
      • @param position the position in the listview */ public void onClick(View itemView, View clickedView, int position); }

    public void setAdapter(ListAdapter adapter) {
    super.setAdapter(new WrapperListAdapterImpl(adapter) {

        @Override
        public View getView(final int position, View view, ViewGroup viewGroup) {
            final View listView = wrapped.getView(position, view, viewGroup);
            // add the action listeners
            if(buttonIds != null && listView!=null) {
                for(int id : buttonIds) {
                    View buttonView = listView.findViewById(id);
                    if(buttonView!=null) {
                        buttonView.findViewById(id).setOnClickListener(new OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if(listener!=null) {
                                    listener.onClick(listView, view, position);
                                }
                            }
                        });
                    }
                }
            }
            return listView;
        }
    });
    

    }
    }

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 prism提示我reinstall prism 如何解决
    • ¥15 asp.core 权限控制怎么做,需要控制到每个方法
    • ¥20 while循环中OLED显示中断中的数据不正确
    • ¥15 这个视频里的stm32f4代码是怎么写的
    • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
    • ¥15 请教SGeMs软件的使用
    • ¥15 自己用vb.net编写了一个dll文件,如何只给授权的用户使用这个dll文件进行打包编译,未授权用户不能进行打包编译操作?
    • ¥50 深度学习运行代码直接中断
    • ¥20 需要完整的共散射点成像代码
    • ¥15 编写vba代码实现数据录入工作