android - How to get last ListView item position -
i created listview radiobutton. listview image below:
and getview is:
public view getview(final int position, view convertview, viewgroup parent) { viewholder holder = null; paymentdata rowitem = getitem(position); layoutinflater minflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); if (convertview == null) { convertview = minflater.inflate( com.android.paypal.homeactivity.r.layout.list_item, null); holder = new viewholder(); holder.radiobtn = (radiobutton) convertview .findviewbyid(com.android.paypal.homeactivity.r.id.rdb_payment_method); holder.btpaymentmethod = (button) convertview .findviewbyid(com.android.paypal.homeactivity.r.id.bt_item_event); convertview.settag(holder); } else holder = (viewholder) convertview.gettag(); holder.radiobtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if ((position != mselectedposition) && (mselectedrb != null)) { mselectedrb.setchecked(false); } mselectedposition = position; mselectedrb = (radiobutton) v; } }); if (mselectedposition != position) { holder.radiobtn.setchecked(false); } else { holder.radiobtn.setchecked(true); if (mselectedrb != null && holder.radiobtn != mselectedrb) { mselectedrb = holder.radiobtn; } } holder.radiobtn.settext(rowitem.getrdbtext()); holder.btpaymentmethod.settext(rowitem.getbttext()); return convertview; }
i want auto checked last radiobutton when screen comes first. how can achieve this.
hold boolean whether user has himself selected anything. let boolean userselected = false;
now in getview()
:
if(position==getcount()-1 && userselected==false) holder.radiobtn.setchecked(true); else holder.radiobtn.setchecked(false);
in onitemclick, when user has made selection himself, set userselected=true;
Comments
Post a Comment