i got row xml listview chronometer
<linearlayout android:layout_width="fill_parent" android:id="@+id/layout_orders_list_row_ll_timer" android:focusable="false" android:layout_height="wrap_content" android:gravity="center_horizontal|right" android:layout_gravity="center"> <chronometer android:text="@+id/chronometer01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/layout_orders_list_row_chr_timer" android:focusable="false" android:focusableintouchmode="false" android:layout_gravity="center" android:enabled="true"> </chronometer> <button android:background="@drawable/check" android:layout_height="wrap_content" android:id="@+id/layout_orders_list_row_bt_done" android:layout_width="wrap_content" android:focusable="false" android:onclick="onrowbuttonclick"> </button>
and want start chronometer each row.i'm getting data database , fill adapter.after i'm connecting each chronometer , trying calculate it.but doesn't work.
simpleadapter simpleadapter = new simpleadapter(this, fillmaps, r.layout.orders_list_row, from, to); listview.setadapter(simpleadapter); (int = 0; < simpleadapter.getcount(); i++) { linearlayout vwparentrow = (linearlayout) simpleadapter.getview(i, null, null); linearlayout childtop = (linearlayout) vwparentrow.getchildat(0); linearlayout childtop2 = (linearlayout) childtop.getchildat(1); final chronometer chrono = (chronometer) childtop2.getchildat(0); chrono.settext("00:00:00"); chrono.setbase(systemclock.elapsedrealtime()); chrono.start(); chrono.setonchronometerticklistener(new onchronometerticklistener() { public void onchronometertick(chronometer arg0) { // todo auto-generated method stub long minutes = ((elapsedtime - chrono.getbase()) / 1000) / 60; long seconds = ((elapsedtime - chrono.getbase()) / 1000) % 60; currenttime = minutes + ":" + seconds; arg0.settext(currenttime); elapsedtime = elapsedtime + 1000; } }); } listview.invalidate();
what i'm doing wrong? maybe there other solution how start chronometer in each row?
to deal problem, created own adapter, since there no standard valuable option suits solution.
public class simpleadapterwithcheckbox extends simpleadapter { public simpleadapterwithcheckbox(context context, list<? extends map<string, ?>> data, int resource, string[] from, int[] to) { super(context, data, resource, from, to); } // method getview start each row in adapter show in listview public view getview(int position, view convertview, viewgroup parent) { view v = super.getview(position, convertview, parent); startchrono(v);// starting each row return v; } private void startchrono(view v){ //here need know structure of layout our element linearlayout vwparentrow = (linearlayout)v; linearlayout childtop = (linearlayout) vwparentrow.getchildat(0); linearlayout childtop2 = (linearlayout) childtop.getchildat(1); //now, chronometer , work wont chronometer chrono = (chronometer) childtop2.getchildat(0); chrono.setbase(systemclock.elapsedrealtime()); chrono.start(); }
}
this not best case scenario, works fine me.
Comments
Post a Comment