android - Add custom checkbox to ArrayAdapter -


i using sqlite database save records, on returning them using code:

 mydb = new dbhelper(this);  arraylist array_list = mydb.getallitems();  arrayadapter arrayadapter=new arrayadapter(this,android.r.layout.simple_list_item_1, array_list);  mrecyclerview =(recyclerview) findviewbyid(r.id.items_list);  obj = (listview)findviewbyid(r.id.listview1);  obj.setadapter(arrayadapter); 

but showing me normal list of items , want display list checkbox on every row. tried using baseadapter , tried recyclerview not working. there way customize simple_list_item_1?

you must write own adapter , in getview() method, inflate own view , pass data it:

myadapter.java

public class myadapter extends baseadapter {  private final arraylist data; private final textview text; private final checkbox check; private final layoutinflater inflater; private final context context;  public myadapter(context context, arraylist data) {     this.context = context;     this.data = data;     inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); }  @override public int getcount() {     return data.size(); }  @override public object getitem(int position) {     return data.get(position); }  @override public long getitemid(int position) {     return data.get(position).getid(); }  @override public view getview(int position, view convertview, viewgroup parent) {      if (convertview == null) {         convertview = inflater.inflate(r.layout.my_item_layout, null, false);     }      text = (textview) convertview.findviewbyid(r.id.text_view);     text.settext(data.get(position));      check = (checkbox) convertview.findviewbyid(r.id.check_box);      return convertview;  } 

and my_item_layout this:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="right"     android:orientation="horizontal">      <textview         android:id="@+id/text_view"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />      <checkbox         android:id="@+id/check_list"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />  </linearlayout> 

with show check boxes....you can't save or change check boxes data


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -