android - ConvertView items partially updated -


i have custom listview in activity , uses convertview pattern , viewholder. works fine, text in items cuted off. seen on screenshots:

screenshot

it looks reuse old view , don't update text length. here part of adapter code:

if (convertview == null) {      viewholder = new viewholderitembool();       layoutinflater inflater = (layoutinflater) context.getsystemservice (context.layout_inflater_service);      if (changeable) {          convertview = inflater.inflate(r.layout.sensor_bool_e, null, true);      } else {          convertview = inflater.inflate(r.layout.sensor_bool, null, true);      }       viewholder.txtname = (textview) convertview.findviewbyid(r.id.txtname);      viewholder.txtdesc = (textview) convertview.findviewbyid(r.id.txtdescript);      viewholder.imgstate = (imageview) convertview.findviewbyid(r.id.img);      convertview.settag(viewholder); } else {      viewholder = (viewholderitembool) convertview.gettag(); } viewholder.txtname.settext(name); if (isimportant()) viewholder.txtname.settypeface(null, typeface.bold); //some code change description field , picture return convertview; 

and here item layout:

<?xml version="1.0" encoding="utf-8"?> <linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/sensor_bool"     android:orientation="horizontal"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:gravity="center_vertical"     android:background="@drawable/sensor_background"     android:longclickable="true">      <imageview         android:id="@+id/img"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/circle_green"         android:padding="10dp"/>      <linearlayout         android:orientation="vertical"         android:layout_width="wrap_content"         android:layout_height="wrap_content">          <textview             android:id="@+id/txtname"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:textsize="@dimen/sensor_text_size"             android:singleline="true"             android:textcolor="@color/sensor_name_color"/>          <textview             android:id="@+id/txtdescript"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:paddingstart="2dp"             android:textsize="@dimen/sensor_desc_size"             android:textcolor="@android:color/secondary_text_light"/>     </linearlayout> </linearlayout> 

if don't use converview , inflate layout each time looks fine. have ideas how fix that?

you need owerride methods of baseadapter show different listview items:

@override public int getviewtypecount() {     return 2; }  @override public int getitemviewtype(int position) {     if (changeable) {         return 0;     } else {         return 1;     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -