android - List view changing views automatically? -


i couldn't find problem,whenever scrolling view change .pls me out...t think android recycle views how override ?

1.before scrolling 2.after scrolling
before scrolling enter image description here

      public class mobilearrayadapter extends arrayadapter<string> { private final context context; private final string[] values; private layoutinflater inflater;  public mobilearrayadapter(context context, string[] values) {     super(context, r.layout.list_mobile, values);       inflater = layoutinflater.from(context);     this.context = context;     this.values = values; }  @override public view getview(int position, view convertview, viewgroup parent) {     view rowview=convertview;     if (rowview == null) {           rowview = inflater.inflate(r.layout.list_mobile, null);          viewholder viewholder = new viewholder();          viewholder.text = (textview) rowview.findviewbyid(r.id.label);                  viewholder.button = (imageview) rowview              .findviewbyid(r.id.logo);           rowview.settag(viewholder);        }         viewholder holder = (viewholder) rowview.gettag();        string s = values[position];         holder.text.settext(s);                if (mp.isplaying()) {               holder.imageview.setimageresource(r.drawable.stop);             } else {               holder.imageview.setimageresource(r.drawable.play);             }       return rowview; }static class viewholder {        public textview text;        public imageview button;       } 

}

in main activity

           protected void onlistitemclick(listview l, view v, int pos, long id) {            if(mp.isplaying() && itemno == pos){           mp.pause();             playing= true;           listmobileactivity.this. imageview.setimageresource(r.drawable.play);          }        else if (playing=true && itemno== pos){           mp.start();           playing=false;             listmobileactivity.this.imageview.setimageresource(r.drawable.stop);       }         if (mp.isplaying()&& itemno!=pos){           listmobileactivity.this.imageview.setimageresource(r.drawable.play);         }       if (itemno!=pos)      {               imageview = (imageview)v. findviewwithtag(pos);               playsample(pos);         }                   listmobileactivity.this.itemno=pos;          //variable i, here, loop.    }  private void playsample( int position)    {             assetfiledescriptor afd =  getapplicationcontext().getresources().openrawresourcefd(songs[position]);              try{                if(mp.isplaying())                 listmobileactivity.  this.mp.stop();                   listmobileactivity.    this.mp.reset();             listmobileactivity.    this.mp.setdatasource(afd.getfiledescriptor(),           afd.getstartoffset(), afd.getdeclaredlength());             listmobileactivity.    this.mp.prepare();   listmobileactivity. this. imageview.setimageresource(r.drawable.stop);         listmobileactivity.this.    mp.setoncompletionlistener(new oncompletionlistener() {                public void oncompletion(mediaplayer mp) {                      listmobileactivity. this.    imageview.setimageresource(r.drawable.play);                 }                 });        listmobileactivity.   this.   mp.start();                  afd.close();            }         catch (illegalargumentexception e)         {             log.e(tag, "unable play audio queue exception: " + e.getmessage(), e);         }         catch (illegalstateexception e)         {             log.e(tag, "unable play audio queue exception: " + e.getmessage(), e);         }         catch (ioexception e)         {             log.e(tag, "unable play audio queue exception: " + e.getmessage(), e);         } } 

i think using custom layout view in list item.

so happens when using custom layout inflate layout , used again next items.

so check condition in custom adapter's view similar this..

if(song2.isplaying) {    imgview.setimage(pauseimage); } else {    imgview.setimage(playimage); } 

it work you.

(its code logic representation check criteria needs set you.)


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -