我想选中所有/取消全选复选框。
这是我的代码。
private class BaseAdpterSendToServer extends BaseAdapter{
String latti,calulationVal;
String longi;
String name;
public BaseAdpterSendToServer(Context context) {
layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return AndroidCamera.imagelistcount;
}
@Override
public Object getItem(int arg0) {
return arg0;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
viewHolder holder;
if(convertView==null){
holder = new viewHolder();
convertView =layoutInflater.inflate(R.layout.row_send_to_server, null);
holder.showImage = (ImageView)convertView.findViewById(R.id.imgView);
holder.txtCalulation = (TextView)convertView.findViewById(R.id.txtCalualtionVal);
holder.txtLatti = (TextView)convertView.findViewById(R.id.txtValLat);
holder.txtLongi = (TextView)convertView.findViewById(R.id.txtValLong);
holder.txtName = (TextView)convertView.findViewById(R.id.txtValName);
holder.checkBox = (CheckBox)convertView.findViewById(R.id.chkBox);
convertView.setTag(holder);
}
else{
holder =(viewHolder)convertView.getTag();
}
int pos = 0;
DBConnect d1 = new DBConnect(getApplicationContext(),"colorCode.db");
pos = position+1;
Cursor c = d1.selectedImageId(pos);
String path = c.getString(1);
calulationVal = c.getString(2);
String s= calulationVal.toString();
latti = c.getString(3);
longi = c.getString(4);
name = c.getString(5);
d1.close();
Bitmap b1 = BitmapFactory.decodeFile(path);
System.out.println("THE BITMAP ISK ----- "+b1);
holder.showImage.setImageBitmap(b1);
holder.txtCalulation.setText(""+s);
holder.txtLatti.setText(""+latti);
holder.txtLongi.setText(""+longi);
holder.txtName.setText(""+name);
bt_f_unsel.setOnClickListener(new OnClickListener() {
}
});
return convertView;
}
class viewHolder{
TextView txtCalulation ,txtLatti, txtLongi,txtName;
ImageView showImage;
CheckBox checkBox;
}
任何帮助对我都有好处。
答案 0 :(得分:0)
您可以创建一个按钮,它将通过您的模型(您拥有的数据)并设置false / true。然后,您应该致电notifyDataSetChanged()
告诉视图更新屏幕
答案 1 :(得分:-4)
我的建议只是制作一个按钮,它将选择/取消选中所有复选框,然后点击按钮制作一个for循环来手动完成。我不知道另一种方式。
通常我们会这样做,
for(int i=0; i < listView.getChildCount(); i++){
RelativeLayout itemLayout = (RelativeLayout)listView.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.MyListViewCheckBox);
cb.setChecked(true);
我希望它会对你有所帮助。