Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2014 10:55
Show Gist options
  • Save anonymous/2442838dd720972b3476 to your computer and use it in GitHub Desktop.
Save anonymous/2442838dd720972b3476 to your computer and use it in GitHub Desktop.
Template about how ot init custom views.
public class MyCustomView extends View {
/**
* Constructor intended for programmatic instantiation of view
*/
public MyCustomView(Context context) {
super(context);
initView();// onFinishInflate is not invoked
}
/**
* Invoked by inflater
*/
public MyCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
// initView is invoked in onFinishInflate
// if invoke it here, child views won't be found
}
/**
* Invoked by inflater when style is set
*/
public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
// initView is invoked in onFinishInflate
// if invoke it here, child views won't be found
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
initView();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment