android - SeekBar in ListView Item is reset -
in application have listview custom item view. each item has own seekbar holds age different persons displayed in listview. problem can scroll seekbar each person if item scrolled out , came in next time seekbar reseted 0. customadapter looks this:
public view getview(int position, view convertview, viewgroup parent) { view row = convertview; peopleholder holder = null; if(row == null) { layoutinflater inflater = layoutinflater.from(context); row = inflater.inflate(layoutresourceid, parent, false); holder = new peopleholder(); final textview tvage = (textview) row.findviewbyid(r.id.age); tvnote.settag(position); holder.age = (seekbar) row.findviewbyid(r.id.agekbar); holder.age.setonseekbarchangelistener(new onseekbarchangelistener() { @override public void onstoptrackingtouch(seekbar seekbar){ } @override public void onstarttrackingtouch(seekbar seekbar){ } @override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { tvage.settext("" + progress); } }); holder.name = (textview) row.findviewbyid(r.id.name); row.settag(holder); } else { holder = (peopleholder) row.gettag(); } people p = data.get(position); holder.name.settext(p.getfullname()); holder.age.setprogress(p.getage()); return row; } private static class peopleholder { textview name; seekbar age; }
be sure change value of person's age when progress changes:
// adding final int can accessed inside listener final int personposition = position; holder.age.setonseekbarchangelistener(new onseekbarchangelistener() { ... @override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { tvage.settext("" + progress); // change age of person in data data.get(personposition).setage(progress); } });
Comments
Post a Comment