本文介绍了而在Android的使用自定义的BaseAdapter存储在列表视图复选框的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表视图是具有图像,文字和复选框我有夸大这种使用BaseAdapter。我想只发送这些选择,但如何存储复选框的状态的图像?可能是我错了,因为我使用baseadapter。你可以建议其他的方式来做到这一点。
i have a listview which is having image, text and checkbox i have inflated this using BaseAdapter. i want to send only those images which are selected but how to store the state of checkbox ?may be i am wrong as i am using baseadapter. you can suggest any other way to do that.
推荐答案
请看看下面我Baseadapter
please look below my Baseadapter
class ImageInfoAdapter extends BaseAdapter{
@Override
public int getCount() {
if(viewcount == 0){
return 0;
}
return viewcount;
}
@Override
public Object getItem(int position) {
return isSentAlList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
final ViewHolder viewHolder;
View rowView=view;
if(rowView==null){
LayoutInflater layoutinflate = LayoutInflater.from(ListPictures.this);
rowView=layoutinflate.inflate(R.layout.listviewayout, parent, false);
viewHolder = new ViewHolder();
viewHolder.textViewisSentFlag = (TextView)rowView.findViewById(R.id.textViewisSentFlag);
viewHolder.imageViewToSent = (ImageView)rowView.findViewById(R.id.imageViewToSent);
viewHolder.checkBoxToSend = (CheckBox)rowView.findViewById(R.id.checkBoxToSend);
rowView.setTag(viewHolder);
}
else{
viewHolder = (ViewHolder) rowView.getTag();
}
viewHolder.ref = position;
Log.i("InfoLog","viewHolder.ref = position; "+viewHolder.ref);
viewHolder.textViewisSentFlag.setText(isSentAlList.get(position));
Bitmap blob = BitmapFactory.decodeByteArray(imageAlList.get(position), 0, imageAlList.get(position).length);
viewHolder.imageViewToSent.setImageBitmap(blob);
viewHolder.checkBoxToSend.setClickable(true);
if(checked.containsKey(""+viewHolder.ref)) ///if this id is present as key in hashmap
{
Log.i("InfoLog","checked.containsKey "+viewHolder.ref);
if(checked.get(""+viewHolder.ref).equals("true")) //also check whether it is true or false to check/uncheck checkbox
{
Log.i("InfoLog","checked.get(position) "+viewHolder.ref);
viewHolder.checkBoxToSend.setChecked(true);
}
else
viewHolder.checkBoxToSend.setChecked(false);
}
else
viewHolder.checkBoxToSend.setChecked(false);
viewHolder.checkBoxToSend.setOnCheckedChangeListener(new OncheckchangeListner(viewHolder));
return rowView;
}//End of method getView
}//End of class ImageInfo
class ViewHolder{
private TextView textViewisSentFlag = null;
private ImageView imageViewToSent = null;
private CheckBox checkBoxToSend = null;
int ref;
}//End of class ViewHolder
和这里是我的oncheckchangedlistener
and here is my oncheckchangedlistener
class OncheckchangeListner implements OnCheckedChangeListener{
ViewHolder viewHolder = null;
public OncheckchangeListner(ViewHolder viHolder)
{
viewHolder = viHolder;
}
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(viewHolder.checkBoxToSend.equals(buttonView))
{
if(!isChecked)
{
Log.i("InfoLog","checked.get before "+checked.get(""+viewHolder.ref));
checked.put(""+viewHolder.ref,"false");
Log.i("InfoLog","checked.get after "+checked.get(""+viewHolder.ref));
}
else
checked.put(""+viewHolder.ref,"true");
}
else
Log.i("InfoLog","i m in checkchange ");
}
}
这篇关于而在Android的使用自定义的BaseAdapter存储在列表视图复选框的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!