Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01dbc2ed authored by Suchi Amalapurapu's avatar Suchi Amalapurapu
Browse files

Cache inflated view to avoid inflation of layouts in preferences

If layout id is specified for a Preference object, convertView is set to null
in its adapter which results in inflation of Preference view in getView each time the Preference object is laid out on the screen.
Just use an instance variable to cache the inflated view nulling it whenever the layout changes and use it in initing the convertView in getView.
parent 81384bf9
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
    private int mLayoutResId = com.android.internal.R.layout.preference;
    private int mWidgetLayoutResId;
    private boolean mHasSpecifiedLayout = false;
    private View mLayoutView;
    
    private OnPreferenceChangeInternalListener mListener;
    
@@ -336,7 +337,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
        if (!mHasSpecifiedLayout) {
            mHasSpecifiedLayout = true;
        }
        
        mLayoutView = null;
        mLayoutResId = layoutResId;
    }
    
@@ -360,6 +361,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
     * @see #setLayoutResource(int)
     */
    public void setWidgetLayoutResource(int widgetLayoutResId) {
        mLayoutView = null;
        mWidgetLayoutResId = widgetLayoutResId;
    }

@@ -387,7 +389,10 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
     */
    public View getView(View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = onCreateView(parent);
            if (mLayoutView == null) {
                mLayoutView = onCreateView(parent);
            }
            convertView = mLayoutView;
        }
        onBindView(convertView);
        return convertView;