Page 202 - MDP2022-2
P. 202
private CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener;
public OneClickView(Context context) {
super(context);
initView();
}
public OneClickView(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
getAttrs(attrs);
}
public OneClickView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
initView();
getAttrs(attrs, defStyle);
}
private void initView() {
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater) getContext().getSystemService(infService);
View v = li.inflate(R.layout.layout_esset, this, false);
addView(v);
bg = findViewById(R.id.bg);
symbol = findViewById(R.id.symbol);
text = findViewById(R.id.text);
power = findViewById(R.id.power);
power.setOnCheckedChangeListener(this);
}
public interface OnCheckedChangeListener {
void onCheckedChanged(CompoundButton buttonView, boolean isChecked);
}
public void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener mListen
er) {
mOnCheckedChangeListener = mListener;
}
@Override