Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've developed this class to pre-inflate a pool of views and reuse it everytime I need. I've gained seconds in performance while updating UI, which is quite impressive.</p> <p>My Logcat says:</p> <pre><code>updating UI inflating on demand &gt;&gt; 2136mS updating UI reusing from pool &gt;&gt; 937mS </code></pre> <p>Here is my class, just don't mind my clumsy Java coding style, I'm a C++ embedded programmer.</p> <pre><code>import java.util.ArrayList; import java.util.List; import android.view.LayoutInflater; import android.view.View; public class ViewPool { private List&lt;View&gt; mViews; private LayoutInflater mInf; private int mIdx; private int mResource; /** * Constructor, gives Inflater and resource ID to inflate * @param mInf Layout inflater * @param rID Resource ID of view to inflate * @para number number of views that must inflate on first initialization */ public ViewPool(LayoutInflater mInf, int rID, int number) { super(); int idx; mViews = new ArrayList&lt;View&gt;(); this.mInf = mInf; mResource = rID; mIdx=0; // index of first used item for(idx=0; idx&lt;number;++idx) { mViews.add((View)mInf.inflate(mResource, null)); } } /** * Start from first item of pool */ public void Reset() { mIdx=0; } /** * Get a view from pool, if no more views on pool, inflate more * @return */ public View GetView() { View retval; retval = mViews.get(mIdx); ++mIdx; if(mIdx == mViews.size()) // no more views in pool?? mViews.add((View)mInf.inflate(mResource, null)); // inflate more return(retval); } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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