梁君 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 自动识别图像目标并判断
      • ¥30 BP神经网络遥感图像分类问题
      • ¥20 新闻小程序6万人在线
      • ¥15 Fluent轴流风扇模拟
      • ¥15 基于GPS的自行车定位系统设计
      • ¥15 idea中安装matplotlib模块完成,运行还是显示无安装
      • ¥15 robotframework 运行报错
      • ¥60 C# (VS2015) 用HttpWebRequest get 方式 与 post 方式
      • ¥30 yolo侦测mammogram总是没有好结果,求经验
      • ¥380 網頁顯示MT4後台數據