I just wanted to make sure I understand the reasons behind decisions so I can become a better programmer.
The book has us add a LayoutInflater parameter in our CrimeHolder constructor, and then we make a LayoutInflater in our CrimeAdapter and pass it in.
In CrimeHolder:
private CrimeHolder(LayoutInflater inflater, ViewGroup parent) { super(inflater.inflate(R.layout.list_item_crime, parent, false)); }
In CrimeAdapter:
public CrimeHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); return new CrimeHolder(layoutInflater, parent); }
But would there be anything wrong with just getting the inflater inside of the CrimeHolder constructor instead?
Would this be considered unsafe or bad practice for any reason? It seems like slightly less complexity.
In CrimeHolder:
private CrimeHolder(ViewGroup parent) { super(LayoutInflater.from(getActivity()).inflate(R.layout.list_item_crime, parent, false)); }
In CrimeAdapter:
public CrimeHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new CrimeHolder(parent); }
Thanks!