当前位置: 代码迷 >> Android >> 关于LiswView CheckBox 全选有关问题
  详细解决方案

关于LiswView CheckBox 全选有关问题

热度:103   发布时间:2016-05-01 21:43:25.0
关于LiswView CheckBox 全选问题
现在的问题是 只能全选屏幕的的所有集合

 不能把超出屏幕的checkBox 选中

求 如何解决!
Java code
package com.eastcom.intelligentanswer.ui;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.Activity;import android.app.Dialog;import android.app.ProgressDialog;import android.content.Context;import android.content.Intent;import android.database.Cursor;import android.os.AsyncTask;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.BaseAdapter;import android.widget.Button;import android.widget.CheckBox;import android.widget.ListView;import android.widget.RelativeLayout;import android.widget.TextView;import android.widget.Toast;import com.eastcom.intelligentanswer.R;import com.eastcom.intelligentanswer.dao.CallingDao;import com.eastcom.intelligentanswer.db.MySqlHelper;import com.eastcom.intelligentanswer.http.message.CallInterInfo;import com.eastcom.intelligentanswer.vo.RingIntentObject;public class CallInter extends Activity implements OnClickListener {    String inflater = Context.LAYOUT_INFLATER_SERVICE;    LayoutInflater layoutInflater;    private CallInterAdapter caAdapter = null;    private Button back, bt_ci_select;    Dialog dialog;    private Context context;    ArrayList<CallInterInfo> interlist = new ArrayList<CallInterInfo>();    private static final int DIALOG_KEY = 0;    TextView emptytextView;    ListView listView;    RelativeLayout llr, sasd;    CheckBox check;    private List<String> data;    // 选中的手机号    protected String numberStr = "";    protected String[] autoContact = null;    protected String rowid = "";    protected void onCreate(Bundle savedInstanceState) {        // TODO Auto-generated method stub        super.onCreate(savedInstanceState);        setContentView(R.layout.callinter);        context = CallInter.this;        listView = (ListView) findViewById(R.id.callinter_list);        back = (Button) findViewById(R.id.back);        back.setOnClickListener(this);        bt_ci_select = (Button) findViewById(R.id.bt_ci_select);        // 开始执行事件        new GetContactTask().execute("");        // 单机listView控件事件        listView.setOnItemClickListener(new OnItemClickListener() {            public void onItemClick(AdapterView<?> parent, View view,                    int position, long id) {                // TODO Auto-generated method stub                check = (CheckBox) view.findViewById(R.id.cb_inter);                llr = (RelativeLayout) view.findViewById(R.id.rlt_callInter);                if (check.isChecked()) {                    check.setChecked(false);                    numberStr = numberStr.replaceAll(interlist.get(position)                            .getCallInterNumber(), "");                    rowid = rowid.replaceAll(                            interlist.get(position).getRowid(), "");                    interlist.get(position).isCheck = false;                } else {                    CallInterInfo item = interlist.get(position);                    check.setChecked(true);                    numberStr = interlist.get(position).getCallInterNumber();                    rowid = interlist.get(position).getRowid();                    interlist.get(position).isCheck = true;                }            }        });        bt_ci_select.setOnClickListener(new OnClickListener() {            public void onClick(View v) {                // TODO Auto-generated method stub                int n = interlist.size();                for (int index = 0; index < listView.getChildCount(); index++) {                    View view = listView.getChildAt(index);                    CheckBox check = (CheckBox) view                            .findViewById(R.id.cb_inter);                    check.setChecked(true);                                        numberStr = interlist.get(index).getCallInterNumber();                    rowid = interlist.get(index).getRowid();                    interlist.get(index).isCheck = true;                }                // 刷新页面 回传数据                Toast.makeText(context, "已全选", 20).show();            }        });    }    // 弹出"查看"对话框    @Override    protected Dialog onCreateDialog(int id) {        switch (id) {        case DIALOG_KEY: {            ProgressDialog dialog = new ProgressDialog(this);            dialog.setMessage("获取拦截名单中...请稍候");            dialog.setIndeterminate(true);            dialog.setCancelable(true);            return dialog;        }        }        return null;    }    // 开始查询    private class GetContactTask extends AsyncTask<String, String, String> {        public String doInBackground(String... params) {            // 从本地手机中获取            GetBlackList();            return "";        }        @Override        protected void onPreExecute() {            showDialog(DIALOG_KEY);        }        @Override        public void onPostExecute(String Re) {            // 绑定LISTVIEW            if (interlist.size() == 0) {                Toast.makeText(context, "没有拦截记录!", 40).show();            } else {                caAdapter = new CallInterAdapter(context, interlist);                listView.setAdapter(caAdapter);                listView.setTextFilterEnabled(true);                // 编辑AUTOCOMPLETE数组                autoContact = new String[interlist.size()];                for (int c = 0; c < interlist.size(); c++) {                    autoContact[c] = interlist.get(c).CallInterName + "("                            + interlist.get(c).CallInterNumber + ")"                            + interlist.get(c).getRowid();                }            }            removeDialog(DIALOG_KEY);        }    }    // 查询拦截记录    private void GetBlackList() {        MySqlHelper mDbHelper = new MySqlHelper(context);        Cursor notesCursor = mDbHelper.selectCallInterList();        System.out.println("----------------Bigen-----------------");        // 开始查询        while (notesCursor.moveToNext()) {            CallInterInfo callinter = new CallInterInfo();            callinter.CallInterNumber = notesCursor.getString(notesCursor                    .getColumnIndex("calling"));            String number = notesCursor.getString(notesCursor                    .getColumnIndex("calling"));            callinter.Rowid = notesCursor.getString(notesCursor                    .getColumnIndex("_id"));            RingIntentObject rbject = new RingIntentObject(this, number);            if (!rbject.getContactName().equals("")) {                callinter.CallInterName = rbject.getContactName();            } else {                callinter.CallInterName = "未知姓名";            }            callinter.isCheck = false;            interlist.add(callinter);        }        notesCursor.close();        mDbHelper.close();        System.out.println("----------------close-----------------");    }    public void onClick(View v) {        // TODO Auto-generated method stub        switch (v.getId()) {        case R.id.back:            finish();            break;        }    }    public class CallInterAdapter extends BaseAdapter {        private LayoutInflater mInflater;        private HashMap<Integer, Boolean> isSelected;        public CallInterAdapter(Context context,                ArrayList<CallInterInfo> itemList) {            mInflater = LayoutInflater.from(context);            interlist = itemList;            this.isSelected = new HashMap<Integer, Boolean>();        }        public ArrayList<CallInterInfo> getItemList() {            return interlist;        }        public void setItemList(ArrayList<CallInterInfo> itemList) {            interlist = itemList;        }        public int getCount() {            // TODO Auto-generated method stub            return interlist.size();        }        public Object getItem(int position) {            return position;        }        public long getItemId(int position) {            return position;        }        // 这个比较特殊,adapter是在页面变化的时候,重新获取当前页面的数据        public View getView(int position, View convertView, ViewGroup parent) {            // TODO Auto-generated method stub            ViewHolder holder;            if (convertView == null) {                // 获得ViewHolder对象                holder = new ViewHolder();                convertView = mInflater.inflate(R.layout.callinteritem, null);                holder = new ViewHolder();                holder.callName = (TextView) convertView                        .findViewById(R.id.tv_interName);                holder.callNumber = (TextView) convertView                        .findViewById(R.id.tv_interNumber);                holder.callcheck = (CheckBox) convertView                        .findViewById(R.id.cb_inter);                holder.inter_delete = (Button) findViewById(R.id.bt_ci_del);                convertView.setTag(holder);            } else {                // 取出holder                holder = (ViewHolder) convertView.getTag();            }            holder.callName.setText(interlist.get(position).getCallInterName());            holder.callNumber.setText(interlist.get(position)                    .getCallInterNumber());            holder.callcheck.setChecked(interlist.get(position).getIsCheck());            holder.inter_delete.setOnClickListener(new OnClickListener() {                public void onClick(View v) {                    // TODO Auto-generated method stub                    // 点击确认将选中的手机号回传                    Intent intent = getIntent();                    String[] callingStr = rowid.split(",");                    CallingDao callingdb = new CallingDao(context);                    for (int i = 0; i < callingStr.length; i++) {                        if (callingStr[i] != null && !callingStr[i].equals("")) {                            callingdb.delete_call(callingStr[i]);                            setResult(RESULT_OK, intent);                            Toast.makeText(context, "删除成功...正在刷新请稍后", 40)                                    .show();                            intent.setClass(context, CallInter.class);                            startActivity(intent);                            finish();                        } else {                            Toast.makeText(context, "请选择要删除的号码", 40).show();                        }                    }                    callingdb.close();                }            });            convertView.postInvalidate();            return convertView;        }        class ViewHolder {            TextView callName;            TextView callNumber;            CheckBox callcheck;            Button inter_delete;        }        class ViewProgressHolder {            TextView text;        }        public HashMap<Integer, Boolean> getIsSelected() {            return isSelected;        }        public void setIsSelected(HashMap<Integer, Boolean> isSelected) {            this.isSelected = isSelected;        }    }}
  相关解决方案