Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're using the standard pattern for a custom <code>ListAdapter</code> here. Not all views will be recycled e.g. when they are first created to fill the <code>ListView</code>.</p> <p>You may also want to take a reference the the <code>LayoutInflater</code> when you create the adapter to slightly improve efficiency, see snippet below</p> <pre><code> private class AlertListAdapter extends ArrayAdapter&lt; Alert &gt; { private ViewHolder holder; private LayoutInflater mInflater; public AlertListAdapter( Context context, List&lt; Alert &gt; items ) { super( context, R.layout.dashboard_layout, items ); mInflater = LayoutInflater.from( context ); } public View getView( int position, View recycledView, ViewGroup parent ) { if ( recycledView == null || recycledView.getTag() == null ) { recycledView = mInflater.inflate( R.layout.list_item, null ); holder = new ViewHolder(); holder.header = ( LinearLayout ) recycledView.findViewById( R.id.alert_list_item_header ); holder.header_text = ( TextView ) recycledView.findViewById( R.id.alert_list_item_header_text ); holder.header_count = ( TextView ) recycledView.findViewById( R.id.alert_list_item_header_count ); holder.name = ( TextView ) recycledView.findViewById( R.id.alert_list_item_name ); holder.distance = ( TextView ) recycledView.findViewById( R.id.alert_list_item_distance ); recycledView.setTag( holder ); } else { holder = ( ViewHolder ) recycledView.getTag(); } holder.header_text.setText( title.substring( 0, space ) ); holder.name.setText( title.substring( space + 1 ) ); holder.header_count.setText( count ); holder.header.setBackgroundResource( resourceID ); return recycledView; } } </code></pre> <p>Essentially you must always be prepared for <code>v.getTag()</code> to return null and inflate a new <code>View</code> accordingly.</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