Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you remove <code>if(v==null)</code> you are not reusing the views which have already been inflated. If you do that the list view will be a bit sluggish. </p> <p>The best way to do is</p> <pre><code>@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; NavigationListEntry i = getItem(position); if(null == convertView){ convertView = inflateNewView(i.type); holder = (ViewHolder) convertView.getTag(); } else{ //getting tag to obtain the already found views holder = (ViewHolder) convertView.getTag(); if(holder.type != i.type){ convertView = inflateNewView(i.type); holder = (ViewHolder) convertView.getTag(); } } //always update the elements holder.title.setText(i.getTitle()); holder.desc.setText(i.getDesc()); holder.content.setText(i.getContent()); return convertView; } /** * Inflates a new view for the specified type * @return the newly inflated view */ private View inflateNewView(int type){ View convertView = null; switch(type) { case ACTIVE_ENTRY: convertView = inflater.inflate(R.layout.list_nav_row_active, null); break; case HEADER: convertView = inflater.inflate(R.layout.list_nav_row_header, null); break; ... default: convertView = inflater.inflate(R.layout.list_nav_row_active, null); break; } holder = new ViewHolder(); convertView = inflater.inflate(LAYOUT_RESOURCE, null); holder.title = (TextView) convertView.findViewById(R.id.txtTitle); holder.desc = (TextView) convertView.findViewById(R.id.txtDesc); holder.content = (TextView) convertView.findViewById(R.id.txtContent); holder.type = type; //setting tag to reduce hierarchy lookup convertView.setTag(holder); return convertView; } /** * Holder class to improve performance. Helps in reducing view hierarchy lookup */ private static class ViewHolder { TextView title; TextView desc; TextView content; int type; } </code></pre> <p>This is the best way which will atleast attempt to recycle your views. Hope this helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload