Should the parent's context be used when retrieving the LayoutInflater from an ArrayAdatper's GetView method?

573 Views Asked by At

I'm trying reduce redundant calls to LayoutInflater.FromContext from within the GetView method of an ArrayAdapter, so I created a private LayoutInflater member _li and initialized it in the constructor.

However, would it be safer to use the context of the parent view from withinGetView?

var li = LayoutInflater.FromContext(parent.Context);
view = li.Inflate(_layoutId, parent, false);

ArrayAdapter

public class StuffAdapter : ArrayAdapter<Stuff>
{
    private readonly int _layoutId;

    //private readonly Context _context;
    private readonly LayoutInflater _li;

    public StuffAdapter(Context context, int layoutId, List<Stuff> stuff) 
        : base(context, layoutId, stuff)
    {
        _layoutId = layoutId;

        //_context = context;
        _li = LayoutInflater.FromContext(context);
    }

    public override View GetView(int position, View view, ViewGroup parent)
    {
        if (view == null)
        {
            //var li = LayoutInflater.FromContext(_context);
            view = _li.Inflate(_layoutId, parent, false);
        }

        // ...

        return view;
    }
}
0

There are 0 best solutions below