forked from liangfeidotme/MasteringAndroidDataBinding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NameCard.java
62 lines (47 loc) · 1.52 KB
/
NameCard.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.liangfeizc.databinding.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.liangfeizc.databinding.R;
/**
* Created by rufi on 6/9/15.
*/
public class NameCard extends LinearLayout {
private int mAge;
private TextView mFirstName;
private TextView mLastName;
public NameCard(Context context) {
this(context, null);
}
public NameCard(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public NameCard(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NameCard);
try {
mAge = a.getInteger(R.styleable.NameCard_age, 0);
} finally {
a.recycle();
}
init();
}
private void init() {
inflate(getContext(), R.layout.name_card, this);
mFirstName = (TextView) findViewById(R.id.first_name);
mLastName = (TextView) findViewById(R.id.last_name);
}
public void setFirstName(@NonNull final String firstName) {
mFirstName.setText(firstName);
}
public void setLastName(@NonNull final String lastName) {
mLastName.setText(lastName);
}
public void setAge(@IntRange(from=1) int age) {
mAge = age;
}
}