android - ListView returning incorrect position inside getView() -
android - ListView returning incorrect position inside getView() -
i have listview having checkedtextview , textview item in each textview. checkedtextview value populated database table. each value there column having timer value 10,15,30 in database. 1 time checkedtextview checked check there value in timer column , if nowadays set textview timer value updated each second. problem if first element has timer value, textview populated timer mm:ss value. when scroll downwards there other listview item populated same value incorrect.
is because position returning wrong value? had read somewhere view refreshes when scroll. example:if item 1 gets populated value, when scroll find element 6 having value
below adapter class
public class methodlazyadapter extends baseadapter { activity activity; private string[] preparationsteps; private string[] timetoprepare; private string[] arrowvalue; private int [] noofstepsflag; string recipeid; listview list; intent intent; context context; int minutes; int noofsteps; private hashmap<integer, boolean> mischecked = new hashmap<integer, boolean>(); private arraylist<boolean> itemchecked = new arraylist<boolean>(); private static layoutinflater inflater=null; mediaplayer player; string vibratorservice; vibrator vibrator; public methodlazyadapter(activity a,string[] preparationsteps,string [] timetoprepare,string [] arrowvalue,int noofsteps,listview list) { this.activity = a; this.preparationsteps = preparationsteps; this.timetoprepare= timetoprepare; this.arrowvalue=arrowvalue; this.list=list; this.noofsteps = noofsteps; noofstepsflag = new int[noofsteps]; for(int i=0;i<noofsteps;i++){ noofstepsflag[i]=0; itemchecked.add(i, false); } inflater = (layoutinflater)activity.getsystemservice(context.layout_inflater_service); } public view getview(final int position, view convertview, viewgroup parent) { view vi=convertview; if(convertview==null) vi = inflater.inflate(r.layout.method_item, null); final checkedtextview checkedtextview = (checkedtextview)vi.findviewbyid(r.id.checkedtextview); checkedtextview.settext(preparationsteps[position]); final textview textview = (textview)vi.findviewbyid(r.id.textview1); final alertdialog.builder alert = new alertdialog.builder(activity); checkedtextview.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { ((checkedtextview) v).toggle(); if(checkedtextview.ischecked()) itemchecked.set(position, true); else if(!checkedtextview.ischecked()) itemchecked.set(position,false); if(!timetoprepare[position].equals("na") && checkedtextview.ischecked() && noofstepsflag[position]==0){ noofstepsflag[position]=1; playaudio(); new countdowntimer(integer.parseint(timetoprepare[position])*60*1000, 500) { //the timer runs 30 seconds in case public void ontick(long lefttimeinmilliseconds) { long seconds = lefttimeinmilliseconds / 1000; textview.settext(string.format("%02d", seconds / 60) + ":" + string.format("%02d", seconds % 60)); } public void onfinish() { textview.settext("done"); alert.settitle("done!!"); alert.setmessage(arrowvalue[position]); alert.seticon(r.drawable.savai_upma); playaudio(); vibratorservice = context.vibrator_service; vibrator = (vibrator)activity.getsystemservice(vibratorservice); vibrator.vibrate(1000); //vibrate 1sec. alert.setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { // code } }); alert.show(); } }.start(); } } private void playaudio() { // todo auto-generated method stub player = mediaplayer.create(activity, r.raw.facebook_ringtone_pop); player.setoncompletionlistener(new oncompletionlistener() { @override public void oncompletion(mediaplayer player) { // todo auto-generated method stub player.release(); } }); player.start(); } }); /* * checkedtextview click state saved in array itemchecked when row clicked , default set * false. * outside onclick checktextview row checked or unchecked * value stored in array itemchecked. */ checkedtextview.setchecked(itemchecked.get(position)); homecoming vi; } public int getcount() { homecoming preparationsteps.length; } public object getitem(int position) { homecoming position; } public long getitemid(int position) { homecoming position; }
}
the checkedtextview getting toggled correctly textview value beingness populated incorrectly. please help.
android seek reuse view many possible
your checkedtextview
set correctly because set not regarding condition
but alter textview
text if click on checkedtextview
textview
may comes text set (since android reusing view)
android
Comments
Post a Comment