Android user list is very slow when scrolling

Guys, I have a problem with my list. It works so slowly when scrolling can help me. My list is a custom layout using a relative with 3 texts and 1 image of each line with all content retrieved from the Internet. I use a custom adapter and a view holder.

Below are my codes on how I use the adapter.

public class MessageList extends ListActivity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.listarticle); loadFeed(link); setListAdapter(new IconAdapter(this)); } /* This method load xml file and parse it into message object*/ private void loadFeed(String link){ try{ BaseFeedParser parser = new BaseFeedParser(link); messages = parser.parse(); titles = new ArrayList<String>(messages.size()); image = new ArrayList<String>(messages.size()); date_post = new ArrayList<String>(messages.size()); descs = new ArrayList<String>(messages.size()); for (Message msg : messages){ titles.add(msg.getTitle()); image.add(msg.getImageLink().toString()); date_post.add(msg.getDate()); descs.add(msg.getDescription()); } } catch (Throwable t){ Log.e("AndroidNews",t.getMessage(),t); } } /*this is my custom baseadapter */ class IconAdapter extends BaseAdapter{ private LayoutInflater mInflater; public IconAdapter(Context cxt){ mInflater = LayoutInflater.from(cxt); } public class ViewHolder{ private TextView title; private TextView date; private TextView desc; private ImageView thumb; } public View getView(int positiion, View convertView, ViewGroup parent){ ViewHolder holder; if (convertView==null){ convertView = mInflater.inflate(R.layout.row, null); holder = new ViewHolder(); holder.title = (TextView) convertView.findViewById(R.id.title); holder.date = (TextView) convertView.findViewById(R.id.date); holder.desc = (TextView) convertView.findViewById(R.id.deskripsi); holder.thumb = (ImageView) convertView.findViewById(R.id.thumbnail); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } holder.title.setText(titles.get(positiion)); holder.date.setText(date_post.get(positiion)); holder.desc.setText(descs.get(positiion).substring(0, 55)+"..."); Drawable draw = LoadImageFromWebOperation(image.get(positiion)); holder.thumb.setImageDrawable(draw); return convertView; } /* this method take image from url that retrieve from xml*/ public Drawable LoadImageFromWebOperation(String url){ try{ InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; }catch (Exception e){ Log.d("image", url, e); return null; } } @Override public int getCount() { return messages.size(); } @Override public Object getItem(int position) { return messages.get(position); } @Override public long getItemId(int position) { return position; } } 
+6
performance android android-listview scroll
source share
4 answers
  public View getView(int positiion, View convertView, ViewGroup parent){ ... Drawable draw = LoadImageFromWebOperation(image.get(positiion)); ... } 

This is problem. You should never create networks in a user interface thread. Implement some asynchronous task for the job. Alternatively, you can use the traceview tool http://developer.android.com/guide/developing/tools/traceview.html to identify performance bottlenecks.

+12
source share

This is your problem, right here.

 Drawable draw = LoadImageFromWebOperation(image.get(positiion)); 

Instead of re-querying the URLs in getView() , immediately do all your queries and save Drawables in an array, and then use the array inside getView . This will make it much faster ...

+4
source share

Take a look at the link in this answer: Scrolling through large cursor-based adapter lists is faster than much smaller adapter lists in memory

+1
source share
 Please use View Holder pattern in getview. ViewHolder holder = null; String fileName = arrfiles.get(position); if (convertView == null) { holder = new ViewHolder(); LayoutInflater inflator = ((Activity) context).getLayoutInflater(); convertView = inflator.inflate(R.layout.unsubmited_row, parent, false); convertView.setClickable(false); } else { holder = (ViewHolder) convertView.getTag(); } holder.txtFileName = (TextView) convertView .findViewById(R.id.txtFileName); holder.txtisActive = (TextView) convertView .findViewById(R.id.txtIsActive); holder.txtFileName.setText(fileName); convertView.setTag(holder); 
0
source share

All Articles