繁体   English   中英

Android:ActionBox的CheckBox OnChecked侦听器

[英]Android: CheckBox OnChecked Listener for ActionMode

问题:使用api获得了我正在使用的应用程序的复杂性。 api调用包括将api的响应处理到如下的listView中:

在此处输入图片说明

因此,对于listView中的这种布局类型,需要一个自定义(ArrayList)适配器,其代码如下:

public class ArrayListAdapter extends BaseAdapter{

    public Context mContext;
    public LayoutInflater mInflater;
    public ArrayList<HashMap<String,String>> mData;
    private SparseBooleanArray mSelectedItemsIds;


    public ArrayListAdapter(Context context, ArrayList<HashMap<String,String>> data){
        mSelectedItemsIds = new SparseBooleanArray();
        mData = data;
        this.mContext = context;
        mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder vh;

        if(convertView == null){
            vh = new ViewHolder();
            convertView = mInflater.inflate(R.layout.projectlist_frame, null);
            vh.projectTitle = (TextView)convertView.findViewById(R.id.projecttitle);
            vh.projectSector = (TextView)convertView.findViewById(R.id.projectsector);
            vh.cb = (CheckBox)convertView.findViewById(R.id.checkBox1);
            convertView.setTag(vh);

        } else{
            vh = (ViewHolder)convertView.getTag();
        }

        vh.projectTitle.setText(mData.get(position).get("title").toString());
        vh.projectSector.setText(mData.get(position).get("sector").toString());

        return convertView;
    }

    class ViewHolder{
        TextView projectTitle, projectSector;
        CheckBox cb;
    }
}

需要帮助 ActionMode现在将在选中时生成ActionMode 关于很多资料,我意识到需要为此设置一个自定义适配器。 那么如何实现两个适配器? 还是有其他方法? 请帮忙!

只需使用方法vh.cb.setOnCheckedChangeListener()onCheckChangedListener添加到您的CheckBox中vh.cb.setOnCheckedChangeListener()

您必须重写onCheckedChanged(CompoundButton buttonView,boolean isChecked)方法。

只需输入以下内容:

@override
private void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
if(isChecked){
//box is checked
}else{
//box is unchecked
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM