我有一个列表视图,每个项目都包含一个复选框和其他各种文本视图.在主要活动中,我有一个名为listofStuff的对象的ArrayList.在主要活动中,我正在定义和使用自定义基本适配器.在getVIEw方法中,我为复选框定义了一个侦听器,如下所示:
holder.cbCompletionStatus.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if(holder.cbCompletionStatus.isChecked()){ listofStuff.get(position).setComplete(1); } else { listofStuff.get(position).setComplete(0); }; }});
我的问题是我不知道如何访问listofStuff及其中的对象来修改其中的信息.如果希望,if / else语句中的代码可以让我了解我正在尝试执行的 *** 作.只是一个简短的警告,我不仅是AndroID和Java的新手,还是整体编程领域的新手.谢谢.
更新:
因此,我最终自行解决了这个问题.我只需要在Main Activity中将listofStuff ArrayList设为静态.然后,我可以在Main Activity中调用一个静态函数来 *** 作所需的Array列表中的任何数据,如下所示:
MainActivity.checkBoxClicked(result,position);
解决方法:
这是我的课:
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 ImageInfoclass VIEwHolder{ private TextVIEw textVIEwisSentFlag = null; private ImageVIEw imageVIEwToSent = null; private CheckBox checkBoxToSend = null; int ref;}//End of class VIEwHolder
/////////////////////////
这是我的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 "); }}
总结 以上是内存溢出为你收集整理的java-如何处理列表视图中的复选框并从自定义基本适配器发送回信息全部内容,希望文章能够帮你解决java-如何处理列表视图中的复选框并从自定义基本适配器发送回信息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)