java - When I set some items to view.invisible in getView(), others don't appear -


visiin custom adapter getview method, have switch case different types of layout cells. refer 1 layout xml these cells , show/hide elements setvisibility(view....) in first cell, "streamlayout," want show 1 imageview, "boombox". set image view invisible in other layouts, when this, won't show in first one. provide getview method , layout xml:

getview:

@override     public view getview(final int position, view convertview, viewgroup parent) {          holder = null;         int type = getitemviewtype(position);          if (convertview == null) {             convertview = minflater.inflate(r.layout.listview_cell, null);             holder = new viewholder();         } else {             holder = (viewholder) convertview.gettag();         }             switch (type) {                  case stream_layout:                      convertview = minflater.inflate(r.layout.listview_cell, null);                      imageview boombox = (imageview) convertview.findviewbyid(r.id.boombox).setvisibility(view.visible);                         convertview.findviewbyid(r.id.cell_image).setvisibility(view.gone);                          convertview.findviewbyid(r.id.divider).setvisibility(view.gone);                         convertview.findviewbyid(r.id.song).setvisibility(view.gone);                         convertview.findviewbyid(r.id.artist).setvisibility(view.gone);                         convertview.findviewbyid(r.id.bottom_layout).setvisibility(view.gone);                       convertview.settag(holder);                   case talkset_layout:                     convertview.findviewbyid(r.id.boombox).setvisibility(view.gone);                      convertview.findviewbyid(r.id.cell_image).setvisibility(view.gone);                     convertview.findviewbyid(r.id.divider).setvisibility(view.gone);                     convertview.findviewbyid(r.id.playcut).setvisibility(view.gone);                      holder.talkset = (textview) convertview.findviewbyid(r.id.talk_break_text);                     holder.talkset.settext("talkset");                      holder.talkset_icon = (imageview) convertview.findviewbyid(r.id.talk_break_image);                     holder.talkset_icon.setimageresource(r.drawable.temp_talkset);                      convertview.settag(holder);                     break;                  case breakpoint_layout:                      convertview.findviewbyid(r.id.boombox).setvisibility(view.gone);                     convertview.findviewbyid(r.id.cell_image).setvisibility(view.gone);                     convertview.findviewbyid(r.id.divider).setvisibility(view.gone);                     convertview.findviewbyid(r.id.artist).setvisibility(view.gone);                           //convertview.findviewbyid(r.id.boombox).setvisibility(view.gone);                  long l = long.parselong(oslist.get(position).get("hour"));                  calendar calendar = calendar.getinstance();                 calendar.settimeinmillis(l);                 calendar.settimeinmillis(l * 1000);                  int hour = calendar.get(calendar.hour);                  holder.song.settext("breakpoint: "+hour+":00");                      holder.breakpoint = (textview) convertview.findviewbyid(r.id.talk_break_text);                     holder.breakpoint.settext("breakpoint");                      holder.breakpoint_icon = (imageview) convertview.findviewbyid(r.id.talk_break_image);                     holder.breakpoint_icon.setimageresource(r.drawable.temp_talkset);                      convertview.settag(holder);                       break;                  case playcut_layout: //playcut                       convertview = minflater.inflate(r.layout.listview_cell, null);                      convertview.findviewbyid(r.id.boombox).setvisibility(view.gone);                       holder.cell_image = (imageview) convertview.findviewbyid(r.id.cell_image);                      try {                         if(oslist.get(position).get("albumarturl")!=null) {                             picasso                                     .with(context)                                     .load(oslist.get(position).get("albumarturl"))                                     .placeholder(r.drawable.no_album_art)                                     .error(r.drawable.no_album_art).into(holder.cell_image);                         }else{                             picasso                                     .with(context)                                     .load(oslist.get(position).get("artistarturl"))                                     .placeholder(r.drawable.no_album_art)                                     .error(r.drawable.no_album_art).into(holder.cell_image);                         }                      } catch (illegalargumentexception e) {                         holder.cell_image.setimageresource(r.drawable.no_album_art);                     }                      holder.song = (textview) convertview.findviewbyid(r.id.song);                     holder.artist = (textview) convertview.findviewbyid(r.id.artist);                      holder.song.settext(oslist.get(position).get("songtitle"));                     holder.artist.settext(oslist.get(position).get("artistname"));                      convertview.setonclicklistener(new view.onclicklistener() {                         @override                         public void onclick(view v) {                             updateview(position);                         }                     });                      convertview.settag(holder);                     break;                 case null_layout:                      convertview.settag(holder);                     break;              }          return convertview;      } 

my xml

   <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:adjustviewbounds="true"         android:src="@drawable/boombox"         android:id="@+id/boombox"         />      <!-- versatile image view storage either boombox, no album art image, or album art -->      <imageview         android:id="@+id/cell_image"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:adjustviewbounds="true"         android:scaletype="centercrop"         />      <!-- divider between image , data -->      <view         android:id="@+id/divider"         android:layout_width="fill_parent"         android:layout_height="1dp"         android:background="@android:color/darker_gray"/>     <!-- layout bottom half of playcut cells -->      <relativelayout         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:id="@+id/bottom_layout"         android:layout_below="@id/divider">          <!-- data song , artist -->          <relativelayout             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/playcut">              <textview                 android:id="@+id/song"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:textstyle="bold"                 android:gravity="center"              />              <textview                 android:id="@+id/artist"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_below="@id/song"                 android:gravity="center"              />         </relativelayout>          <!-- talkset , breakpoint cell data -->          <relativelayout             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/talk_break"             android:paddingleft="1dp"             android:paddingtop="1dp"             android:paddingbottom="1dp">              <imageview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/talk_break_image"/>              <textview                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:id="@+id/talk_break_text"                 android:layout_torightof="@id/talk_break_image"/>           </relativelayout>          <!-- playcut cell, clicked, displaying facebook, twitter, heart, , search icons -->          <tablelayout             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:stretchcolumns="0,1,2,3,4"             android:paddingbottom="2dp"             android:id="@+id/table">              <tablerow>                  <imageview                     android:layout_width="fill_parent"                     android:layout_height="fill_parent"                     android:id="@+id/twitter_icon"/>                  <imageview                     android:layout_width="fill_parent"                     android:layout_height="fill_parent"                     android:id="@+id/facebook_icon"/>                  <imageview                     android:layout_width="fill_parent"                     android:layout_height="fill_parent"                     android:id="@+id/unclicked_heart_icon"/>                  <imageview                     android:layout_width="fill_parent"                     android:layout_height="fill_parent"                     android:id="@+id/search_icon"/>              </tablerow>         </tablelayout>       </relativelayout>  </linearlayout> 

the reason doesn't work because you're using viewholder maintain reference each ui element adapter items.

because of this, if element set view.gone in first iteration , isn't touched again, remain in state, regardless of how defined in xml.

to work around this, should explicitly set visibility of element in getview() depending on layout using, because if first iteration referencing viewholder , state in, not view inflated xml file.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -