zoukankan      html  css  js  c++  java
  • checkbox的全选、反选、删除(适配器)

    package com.example.adapter;

    import java.util.List;

    import com.example.ay.R;
    import com.example.vo.Flag;

    import android.content.Context;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.CompoundButton.OnCheckedChangeListener;
    import android.widget.ImageView;
    import android.widget.TextView;

    public class LVadapter extends BaseAdapter {
        int[] str = new int[] { R.drawable.a1, R.drawable.a2, R.drawable.a22,
                R.drawable.a3, R.drawable.d3, R.drawable.h7, R.drawable.r,
                R.drawable.r4, R.drawable.s3, R.drawable.tt, R.drawable.vv,
                R.drawable.x1, R.drawable.y6 };

        List<Flag> list;

        public LVadapter(List<Flag> list, Context context) {
            super();
            this.list = list;
            this.context = context;
        }

        Context context;

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

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

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

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            convertView = convertView.inflate(context, R.layout.lv, null);
            ImageView image = (ImageView) convertView.findViewById(R.id.image);
            TextView name = (TextView) convertView.findViewById(R.id.name);
            CheckBox check = (CheckBox) convertView.findViewById(R.id.check);

            image.setImageResource(str[position]);
            name.setText(list.get(position).getName());

            check.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {

                    list.get(position).setFlag(isChecked);

                }
            });
            
            //记录当前复选框的操作
            check.setChecked(list.get(position).isFlag());
            return convertView;
        }

    }

  • 相关阅读:
    Redis学习笔记(九、Redis总结)
    菜鸟刷面试题(二、RabbitMQ篇)
    RabbitMQ学习笔记(八、RabbitMQ总结)
    MongoDB学习笔记(七、MongoDB总结)
    菜鸟刷面试题(一、Java基础篇)
    朋友圈点赞
    队列变换
    犯二的程度
    猴子选大王
    最大销售增幅
  • 原文地址:https://www.cnblogs.com/1995yu/p/5389892.html
Copyright © 2011-2022 走看看