android - listview of songs with checkbox using Aquery unable to save the State of chekckbox while list scrolldown? -
hi have listview of songs checkbox using aquery unable save state of chekckbox while list scrolldown. have 2 arraylist 1 clicking song image & other checkbox if user select chekbox should play song accordingly checkbox arraylist. have used check.setchecked(selectedbox.get(clickedposition).getischeck()); . no
so far have done here
private void createlist() { listaq = new aquery(this); adapter = new arrayadapter<audio>(songlist.this, r.layout.list_row,details) { @override public view getview(final int position, view convertview,final viewgroup parent) { if (convertview == null) { convertview = getlayoutinflater().inflate(r.layout.list_row, parent, false); } final int clickedposition = position; final aquery aq = listaq.recycle(convertview); audio item = getitem(position); aq.id(r.id.moviename).text(item.getalbumname()); aq.id(r.id.songname).text(item.gettitle()); aq.id(r.id.checkbox1).getcheckbox().setselected(item.getischeck()); aq.id(r.id.namelayout).clicked(new onclicklistener() { @override public void onclick(view v) { dialogbuilder(position); } }); check = (checkbox) convertview.findviewbyid(r.id.checkbox1); check.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview,boolean ischecked) { try { if (ischecked) { checkbox = true; if (details.get(clickedposition).getischeck() == false) { selectedbox.add(details.get(clickedposition)); system.out.println(selectedbox.size()); details.get(clickedposition).setischeck(true); } } else { final string name = details.get(clickedposition).getfilename(); (int = 0; <= selectedbox.size(); i++) { if (name.equals(selectedbox.get(i).getfilename())) { selectedbox.remove(i); details.get(clickedposition).setischeck(false); } } } notifydatasetchanged(); } catch (exception e) { e.getmessage(); } } }); try{ } catch (exception e) { // todo: handle exception } url = "drawable/" + item.getthumbnail(); imageresource = getresources().getidentifier(url, null,getpackagename()); aq.id(r.id.song_image).image(imageresource); if (position != playingvalue) { aq.id(r.id.imageplay).invisible(); aq.id(r.id.imageplay).getimageview().bringtofront(); } else { aq.id(r.id.imageplay).visible(); } imageview img = (imageview)convertview.findviewbyid(r.id.song_image); img.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { checkbox = false; selectedbox.clear(); currentsongindex = position; try { if (channelservice.playerflag == 0) { playsong(currentsongindex); } else if ((channelservice.playerflag == 1) || ((channelservice.playerflag == 2))) { if (currentsongindex != playingvalue) { try { final intent serviceintent = new intent( getapplicationcontext(), channelservice.class); stopservice(serviceintent); mplay.setbackgroundresource(r.drawable.play_btn); playsong(currentsongindex); } catch (final illegalstateexception e) { e.printstacktrace(); } } mplay.setbackgroundresource(r.drawable.pause_btn); final intent in = new intent("updatenotification"); sendbroadcast(in); } } catch (final illegalstateexception e) { e.getmessage(); } notifydatasetchanged(); } }); return convertview; } }; aq.id(r.id.listview1).adapter(adapter); }
when scroll down list in android, destroys rows doesn't fit in screen. allways use array of objects save state of each row when android calls getview can ask state of them:
public class audiorow{ public int id; public boolean checked; ... } then @ getview can that:
public view getview(final int position, view convertview,final viewgroup parent) { if (convertview == null) { convertview = getlayoutinflater().inflate(r.layout.list_row, parent, false); } final int clickedposition = position; audiorow ar = audiorows.get(position); if(ar.checked) { //do something; } ... @override public void onclick(view v) { if(ar.checked) ar.checked = false; else ar.checked = true; dialogbuilder(position); } }); i hope helps you.
Comments
Post a Comment