Skip to content

Instantly share code, notes, and snippets.

@samuel22gj
Last active June 9, 2018 10:59
Show Gist options
  • Save samuel22gj/a58b99745f862ad84ed0 to your computer and use it in GitHub Desktop.
Save samuel22gj/a58b99745f862ad84ed0 to your computer and use it in GitHub Desktop.
Android custom view template
public class CustomView extends View {
public CustomView(Context context) {
this(context, null);
}
public CustomView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle) {
// Load attributes
final TypedArray typedArray = context.obtainStyledAttributes(
attrs, R.styleable.CustomView, defStyle, 0);
// mExampleString = a.getString(R.styleable.CustomView_exampleString);
typedArray.recycle();
// Inflate layout
LayoutInflater.from(getContext()).inflate(R.layout.compound_view, this, true);
// thumbnail = (ImageView) findViewById(R.id.thumbnail);
// Do anything you want.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment