Skip to content

Instantly share code, notes, and snippets.

@kmerrell42
Created March 17, 2017 18:40
Show Gist options
  • Save kmerrell42/df17a292d9fc592e5771ad54e8a0e6dd to your computer and use it in GitHub Desktop.
Save kmerrell42/df17a292d9fc592e5771ad54e8a0e6dd to your computer and use it in GitHub Desktop.
Android LayoutInflater.Factory2 for DI example
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Picasso picasso = Picasso.with(this);
LayoutInflater.Factory2 customInflaterFactory = new LayoutInflater.Factory2() {
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
return onCreateView(name, context, attrs);
}
public View onCreateView(final String viewName, Context context, AttributeSet attributeSet) {
if (TextUtils.equals(viewName, MovieSummaryView.class.getName())) {
return new MovieSummaryView(context, attributeSet, picasso);
}
return null;
}
};
getLayoutInflater().setFactory2(customInflaterFactory);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment