android - Very slow listView adapter -
i create listview arrayadapter. every item has many views. code of getview() method:
public view getview(final int position, view convertview, viewgroup parent) { viewholder holder; if (convertview == null) { convertview = minflater.inflate(r.layout.dialog_list_view, null); holder = new viewholder(); holder.date = (textview)convertview.findviewbyid(r.id.date); holder.multi_chat = (imageview)convertview.findviewbyid(r.id.multi_chat); holder.my_userpick = (imageview)convertview.findviewbyid(r.id.my_userpic); holder.name = (textview)convertview.findviewbyid(r.id.name); holder.photo1 = (imageview)convertview.findviewbyid(r.id.photo1); holder.photo2 = (imageview)convertview.findviewbyid(r.id.photo2); holder.photo31 = (imageview)convertview.findviewbyid(r.id.photo31); holder.photo32 = (imageview)convertview.findviewbyid(r.id.photo32); holder.photo33 = (imageview)convertview.findviewbyid(r.id.photo33); holder.photo41 = (imageview)convertview.findviewbyid(r.id.photo41); holder.photo42 = (imageview)convertview.findviewbyid(r.id.photo42); holder.photo43 = (imageview)convertview.findviewbyid(r.id.photo43); holder.photo44 = (imageview)convertview.findviewbyid(r.id.photo44); holder.text = (textview)convertview.findviewbyid(r.id.text); holder.userpic = (imageview)convertview.findviewbyid(r.id.userpic); holder.userpick2 = convertview.findviewbyid(r.id.userpick2); holder.userpick3 = convertview.findviewbyid(r.id.userpick3); holder.userpick4 = convertview.findviewbyid(r.id.userpick4); holder.wrapper = (relativelayout)convertview.findviewbyid(r.id.wrapper); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } if (dialogs != null) { if (position == (this.getcount() - 1)) { if (dialogs != null) { if (dates.size() > 1) { dialogs.getdialogs(dates.size()+20); } } } } if (dates.get(position).getchatid() != 0) { holder.name.settext(dates.get(position).gettitle()); holder.multi_chat.setvisibility(view.visible); } else { holder.name.settext(dates.get(position).getuiddates()); holder.multi_chat.setvisibility(view.gone); } if (dates.get(position).getreadstate() == 0) { holder.wrapper.setbackgroundcolor(getresources().getcolor(r.color.conversation_list_no_read)); } else { holder.wrapper.setbackgroundcolor(android.r.color.white); } holder.text.settext(dates.get(position).getbody()); int date = dates.get(position).getdate(); java.util.date time = new java.util.date((long) date * 1000); if ((time.getdate() == current_date.getdate()) && (time.getmonth() == current_date.getmonth()) && (time.getyear() == current_date.getyear())) { holder.date.settext(time.gethours() + ":" + time.getminutes()); } else if ((time.getdate() == (current_date.getdate() - 1)) && (time.getmonth() == current_date.getmonth()) && (time.getyear() == current_date.getyear())) { holder.date.settext("вÑеÑа"); } else { holder.date.settext(time.getdate() + "." + time.getmonth() + "." + (time.getyear()+1900)); } if(!dates.get(position).getphotointext().equals("")) { loaderwithoutcut.displayimage(dates.get(position).getphotointext(), holder.my_userpick, false); holder.my_userpick.setvisibility(view.visible); holder.text.setbackgrounddrawable(getresources().getdrawable(r.drawable.dialog_rect_bg)); holder.text.setpadding(10, 0, 10, 0); holder.text.setgravity(gravity.center_vertical); holder.text.setsingleline(true); holder.text.setellipsize(textutils.truncateat.end); } else { holder.my_userpick.setvisibility(view.gone); holder.text.setbackgroundcolor(getresources().getcolor(android.r.color.transparent)); holder.text.setpadding(0, 0, 0, 0); holder.text.setsingleline(false); holder.text.setgravity(gravity.top); } arraylist photos = dates.get(position).getuidphotos(); if (dates.get(position).getchatid() == 0) { if (photos.size() == 1) { loaderwithoutcut.displayimage((string) photos.get(0), holder.userpic, false); holder.userpick2.setvisibility(view.gone); holder.userpick3.setvisibility(view.gone); holder.userpick4.setvisibility(view.gone); holder.userpic.setvisibility(view.visible); } } else { if ((photos.size() < 3) && (photos.size()>0)) { if (photos.size() == 1) { holder.photo1.setvisibility(view.gone); loaderwithcut.displayimage((string) photos.get(0), holder.photo2, true); } else { holder.photo1.setvisibility(view.visible); loaderwithcut.displayimage((string) photos.get(1), holder.photo2, true); if (!((string) photos.get(1)).equals((string) photos.get(0))) { loaderwithcut.displayimage((string) photos.get(0), holder.photo1, true); } else { holder.photo1.setvisibility(view.gone); } } holder.userpic.setvisibility(view.gone); holder.userpick2.setvisibility(view.visible); holder.userpick3.setvisibility(view.gone); holder.userpick4.setvisibility(view.gone); } if (photos.size() == 3) { loaderwithcut.displayimage((string) photos.get(0), holder.photo31, true); loaderwithoutcut.displayimage((string) photos.get(1), holder.photo32, false); loaderwithoutcut.displayimage((string) photos.get(2), (imageview) holder.photo33, false); holder.userpic.setvisibility(view.gone); holder.userpick2.setvisibility(view.gone); holder.userpick3.setvisibility(view.visible); holder.userpick4.setvisibility(view.gone); } if (photos.size() >= 4) { loaderwithoutcut.displayimage((string) photos.get(0), holder.photo41, false); loaderwithoutcut.displayimage((string) photos.get(1), holder.photo42, false); loaderwithoutcut.displayimage((string) photos.get(2), holder.photo43, false); loaderwithoutcut.displayimage((string) photos.get(3), holder.photo44, false); holder.userpic.setvisibility(view.gone); holder.userpick2.setvisibility(view.gone); holder.userpick3.setvisibility(view.gone); holder.userpick4.setvisibility(view.visible); } } if (photos.size() == 0) { holder.userpick2.setvisibility(view.gone); holder.userpick3.setvisibility(view.gone); holder.userpick4.setvisibility(view.gone); } final viewholder holder2 = holder; convertview.setonfocuschangelistener(new view.onfocuschangelistener() { @override public void onfocuschange(view v, boolean hasfocus) { textview text = holder2.text; textview date = holder2.date; textview name = holder2.name; if (hasfocus) { text.settextcolor(getresources().getcolor(android.r.color.white)); date.settextcolor(getresources().getcolor(android.r.color.white)); name.settextcolor(getresources().getcolor(android.r.color.white)); } else { text.settextcolor(getresources().getcolor(r.color.dialog_text)); date.settextcolor(getresources().getcolor(r.color.dialog_date)); name.settextcolor(getresources().getcolor(r.color.friends_text_color)); } } }); return convertview; }
problem - list view scrolling working slow. how can solve problem? code of layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:background="@drawable/list_drawable_settings"> <relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:id="@+id/wrapper"> <linearlayout android:layout_width="52dip" android:id="@+id/images" android:layout_margin="6dip" android:layout_height="58dip"> <com.vk.messenger.views.roundedconersimageview android:id="@+id/userpic" android:layout_height="wrap_content" android:layout_width="wrap_content" /> <linearlayout android:layout_width="wrap_content" android:id="@+id/userpick2" android:layout_height="wrap_content"> <linearlayout android:layout_width="26dip" android:layout_height="58dip"> <com.vk.messenger.views.scalledimageview android:scaletype="fitcenter" android:croptopadding="true" android:layout_width="26dip" android:layout_height="58dip" android:id="@+id/photo1"/> </linearlayout> <linearlayout android:layout_width="26dip" android:layout_height="58dip"> <com.vk.messenger.views.scalledimageview android:layout_width="26dip" android:layout_height="58dip" android:scaletype="fitcenter" android:croptopadding="true" android:id="@+id/photo2"/> </linearlayout> </linearlayout> <linearlayout android:layout_width="wrap_content" android:id="@+id/userpick3" android:layout_height="wrap_content"> <imageview android:layout_width="26dip" android:layout_height="58dip" android:id="@+id/photo31" ></imageview> <linearlayout android:layout_width="26dip" android:id="@+id/userpick3" android:layout_height="58dip" android:orientation="vertical"> <imageview android:layout_width="26dip" android:scaletype="fitcenter" android:croptopadding="true" android:layout_height="26dip" android:id="@+id/photo32" ></imageview> <imageview android:layout_width="26dip" android:scaletype="fitcenter" android:croptopadding="true" android:layout_height="29dip" android:id="@+id/photo33" ></imageview> </linearlayout> </linearlayout> <linearlayout android:layout_width="52dip" android:id="@+id/userpick4" android:layout_height="58dip" android:orientation="horizontal"> <linearlayout android:layout_width="26dip" android:layout_height="58dip" android:orientation="vertical"> <imageview android:layout_width="26dip" android:layout_height="29dip" android:id="@+id/photo41" ></imageview> <imageview android:layout_width="26dip" android:layout_height="29dip" android:id="@+id/photo42" ></imageview> </linearlayout> <linearlayout android:layout_width="26dip" android:layout_height="58dip" android:orientation="vertical"> <imageview android:layout_width="26dip" android:layout_height="29dip" android:id="@+id/photo43" ></imageview> <imageview android:layout_width="26dip" android:layout_height="29dip" android:id="@+id/photo44" ></imageview> </linearlayout> </linearlayout> </linearlayout> <relativelayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centervertical="true" android:layout_torightof="@id/images" android:layout_marginleft="4dip"> <linearlayout android:layout_width="fill_parent" android:orientation="vertical" android:id="@+id/left" android:layout_height="wrap_content"> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <imageview android:id="@+id/multi_chat" android:visibility="invisible" android:paddingtop="3dip" android:paddingright="2dip" android:src="@drawable/multi_chat" android:layout_height="wrap_content" android:layout_width="wrap_content" /> <com.vk.messenger.views.textviewmyriadpro android:id="@+id/name" android:text="" android:singleline="true" android:ellipsize="end" android:layout_centervertical="true" android:textcolor="@color/friends_text_color" android:textsize="16dip" android:textstyle="bold" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1"/> <com.vk.messenger.views.textviewhelvetica android:id="@+id/date" android:layout_marginleft="6dip" android:gravity="right" android:layout_marginright="6dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/dialog_date" android:textsize="13dip"/> </linearlayout> <linearlayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:layout_margintop="2dip"> <com.vk.messenger.views.roundedconersimageview android:id="@+id/my_userpic" android:visibility="gone" android:paddingright="2dip" android:layout_height="30dip" android:layout_width="30dip"/> <com.vk.messenger.views.textviewhelvetica android:id="@+id/text" android:text="ÑекÑÑ" android:layout_below="@id/name" android:layout_centervertical="true" android:layout_marginleft="3dip" android:layout_marginright="6dip" android:textcolor="@color/dialog_text" android:textsize="13dip" android:layout_height="fill_parent" android:layout_width="fill_parent" /> </linearlayout> </linearlayout> </relativelayout> </relativelayout> </linearlayout>
i think doing in getview, code has run every visible list item every time try scroll, there happening.
also loadwithcut/loadwitoutcut? loading images from? manipulating images in getview?
i first try move object creation out of getview if possible, logging in various methods see slowness occurring.
Comments
Post a Comment