Android ListView Radio Feature

Source: Internet
Author: User

Control is implemented inside the adapter GetView.


private int selectposition =-1;class payadapter extends baseadapter{@Overridepublic int GetCount () {//TODO auto-generate D method Stubreturn paylist==null?0:paylist.size ();} @Overridepublic Object getItem (int position) {//TODO auto-generated method Stubreturn paylist.get (position);} @Overridepublic long Getitemid (int position) {//TODO auto-generated method Stubreturn position;} @Overridepublic View GetView (final int position, view Convertview, ViewGroup parent) {Viewholder holder = null;if (CONVERTV Iew = = null) {Convertview = Layoutinflater.from (context). Inflate (r.layout.pay_listview_item_layout,null); holder = new Viewholder (); holder.image = (ImageView) Convertview.findviewbyid (r.id.pay_bank_icon_imageview); holder.title = ( TextView) Convertview.findviewbyid (r.id.pay_bank_title_textview); holder.description = (TextView) Convertview.findviewbyid (r.id.pay_bank_description_textview); Holder.radio = (RadioButton) Convertview.findviewbyid (R.ID.PAY_SELECT_RADIOBTN); Convertview.settag (holder);} Else{holder = (Viewholder) Convertview.gettag ();} Pay pay = (pay) GetItem (position), Holder.image.setImageResource (Getresources (). Getidentifier (Pay.getimage (), " Drawable ", Context.getpackagename ())); Holder.title.setText (Pay.gettitle ()); Holder.description.setText ( Pay.getdescription ()); Holder.radio.setOnCheckedChangeListener (new Oncheckedchangelistener () {@Overridepublic void OnCheckedChanged (Compoundbutton Buttonview, Boolean isChecked) {if (isChecked) {selectposition = position;} Notifydatasetchanged ();}}); if (selectposition==position) {holder.radio.setChecked (true);} Else{holder.radio.setchecked (false);} if (position==0) {holder.radio.setChecked (true);} return Convertview;}} Class Viewholder{imageview image; TextView title; TextView description; RadioButton Radio;}


Android ListView Radio Feature

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.