Note that there are some explanatory texts on larger screens.

plurals
  1. POImageView.setImageResource is the culprit for my stuttering ListView, what now?
    primarykey
    data
    text
    <p>So my ListView was stuttering on my phone, so I used TraceView to determine the culprit.</p> <pre><code> @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = inflater.inflate(R.layout.menu_row, parent, false); ViewHolder holder = new ViewHolder(); // setting other Views. holder.icon = (ImageView) view.findViewById(R.id.icon); view.setTag(holder); return view; } @Override public void bindView(View v, Context context, Cursor c) { ViewHolder holder = (ViewHolder) v.getTag(); // getting other Views String imgUrl = c.getString(6); int resource = getResources().getIdentifier(imgUrl, "drawable", getActivity().getPackageName()); if (resource != 0) { holder.icon.setImageResource(resource); return; } } </code></pre> <p>As expected newView and bindView were taking the most time from all of my method calls.</p> <ul> <li><strong>newView() is spending all of it's time in the inflater.inflate(R.layout.menu_row, parent, false); call</strong></li> <li><strong>bindView() is spending all of it's time in holder.icon.setImageResource(resource);</strong></li> </ul> <p>I've dug deeper into setImageResource and the call hierarchy was this: (all of these methods were 99% of the cpu time):</p> <ol> <li>ImageView.setImageResource</li> <li>ImageView.resolveUri</li> <li>Resources.getDrawable</li> <li>Resources.loadDrawable</li> <li>Drawable.createFromResourceStream</li> <li>BitmapFactory.decodeResourceStream</li> <li>BitmapFactory.decodeStream</li> <li>BitmapFactory.nativeDecodeAsset (which is the method whose <strong>self</strong> is causing the most cpu time).</li> </ol> <p><strong>What can I do to optimize my ListView? (all of my images are not more than 15 KB in disk size).</strong></p> <p>This is the ImageView I'm setting xml:</p> <pre><code>&lt;ImageView android:id="@+id/icon" android:layout_width="0dp" android:layout_height="85dp" android:layout_gravity="center_vertical" android:layout_marginRight="10dp" android:layout_weight="25" android:adjustViewBounds="true" android:contentDescription="@string/description_item" android:minHeight="85dp" android:minWidth="85dp" android:scaleType="fitCenter" /&gt; </code></pre> <p><strong>EDIT:</strong> I've changed the ImageView xml to:</p> <pre><code>&lt;ImageView android:id="@+id/icon" android:layout_width="85dp" android:layout_height="85dp" android:scaleType="center" android:contentDescription="@string/description_item" /&gt; </code></pre> <p>Didn't provide any performance gain.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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