json - Unable to the the Image to the desired position in android's custom listview -
recently, i've managed make custom listview in android displays image in list. however, have 1 problem cannot solve. tried simple, 1. display blinking icon list item has same date json data via web. 2. display image 2nd , 3rd position of listview. 3. , rest of list items, there no images shown.
i have simple codition in custom adapter's getview method compares current date date gets retreived json data via web. i've set function i'm using below.
if current date equal date json data, display image blinks(for testing purposes i'm using 2015/05/14). if position equal 2nd or 3 rd position display icon. else show nothing. however, images shows @ random positions of listview. there bug in code? how possible not show icons doesn't meet conditions ?
if (days.get(position).trim().tostring().equals("2015/05/14")||days.get(position).trim().tostring()=="2015/05/14") { holder.left.setbackgroundresource(r.drawable.blinker); animationdrawable frameanimation = (animationdrawable) holder.left .getbackground(); // start animation (looped playback default). frameanimation.start(); }else{ holder.left.setimageresource(android.r.color.transparent); } if(position==1||position==2){ holder.left.setimageresource(r.drawable.new1); }else{ holder.left.setimageresource(android.r.color.transparent); } if(position==getcount()-1){ holder.left.setimageresource(android.r.color.transparent); } return convertview; }
if (days.get(position).trim().tostring().equals("2015/05/14")||days.get(position).trim().tostring()=="2015/05/14") { holder.left.setbackgroundresource(r.drawable.blinker); animationdrawable frameanimation = (animationdrawable) holder.left .getbackground(); // start animation (looped playback default). frameanimation.start(); // set variable index of blinking row mblinkingindex = position; }else{ holder.left.setimageresource(android.r.color.transparent); }
in subsequent calls of getview()
, use mblinkingindex
determine.
because need set 2nd , 3rd row drawable new1
if((position = (mblinkingindex+1) || (position == (mblinkingindex+2)){ // row special holder.left.setimageresource(r.drawable.new1); }else{ // row not special holder.left.setimageresource(android.r.color.transparent); }
so, getview()
:
if (days.get(position).trim().tostring().equals("2015/05/14")||days.get(position).trim().tostring()=="2015/05/14") { holder.left.setbackgroundresource(r.drawable.blinker); animationdrawable frameanimation = (animationdrawable) holder.left .getbackground(); // start animation (looped playback default). frameanimation.start(); // set variable index of blinking row mblinkingindex = position; }else{ holder.left.setimageresource(android.r.color.transparent); } if((position = (mblinkingindex+1) || (position == (mblinkingindex+2)){ // row special holder.left.setimageresource(r.drawable.new1); }else{ // row not special holder.left.setimageresource(android.r.color.transparent); }
Comments
Post a Comment