java - Start chronometer on each row of Listview in android -


i have list items on 1 list layout among items have there chronometer need start on each row ,other items come database, when activity launches chronometer stays on 00:00. please me , did many research tell me in can use adapter not familiar it, don't know if there not way without using adapter .

mainactivity .java:

     private arraylist<hashmap<string, string>> userlist;     @override         protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);             mylist = (listview)findviewbyid(r.id.listview);       inflatedview =      getlayoutinflater().inflate(r.layout.payement_timing_list_adapter_view, null);        chronometer = (chronometer)         inflatedview.findviewbyid(r.id.chronometer);             if (userlist.size() != 0) {         //set user array list in listview         adapter = new simpleadapter(getapplicationcontext(), userlist, r.layout.payement_timing_list_adapter_view,                 new string[]{"driver_fullname", "plate_no", "parking_name"},                 new int[]{r.id.drivername, r.id.plateno, r.id.pname});         mylist.setadapter(adapter);            }        mylist.setonitemclicklistener(new adapterview.onitemclicklistener() {        @override           public void onitemclick(adapterview<?> parent,                                 view view, int position, long id) {                 log.d("my position",""+position);                  ((chronometer)inflatedview.findviewbyid(r.id.chronometer)).mylist.     (position).start();             chronometer.start();         }            }); 

you need use custom adapter listview, , declare chronometer in getview method each row.

a custom adapter onle this:

public class customadapter extends baseadapter{       arraylist<hashmap<string, string>> users;   context context;   private static layoutinflater inflater=null;    public customadapter(mainactivity mainactivity, arraylist<hashmap<string, string>> userslist) {     // todo auto-generated constructor stub     users = userslist;     context=mainactivity;     inflater = ( layoutinflater )context.getsystemservice(context.layout_inflater_service);   }    @override   public int getcount() {     // todo auto-generated method stub     return items.length;   }    @override   public object getitem(int position) {     // todo auto-generated method stub     return position;   }    @override   public long getitemid(int position) {     // todo auto-generated method stub     return position;   }    public class holder   {     textview tv;     ...     chronometer cr;   }    @override   public view getview(final int position, view convertview, viewgroup parent) {     // todo auto-generated method stub     holder holder=new holder();     view rowview;       //create custom layout row view chronometer on , here      rowview = inflater.inflate(r.layout.custom_row_item, null);       holder.tv=(textview) rowview.findviewbyid(r.id.textview1);      ...      holder.cr=(chronometer) rowview.findviewbyid(r.id.chronometer);        cr.start();       holder.tv.settext("get text need users list here");          return rowview;   }  }  

then declare , use custom adapter like:

customadapter myadapter = new customadapter(youractivity.this, userlist); mylist.setadapter(myadapter); 

hope helps :)


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -