Last active
June 9, 2018 10:59
-
-
Save samuel22gj/a58b99745f862ad84ed0 to your computer and use it in GitHub Desktop.
Android custom view template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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