【发布时间】:2019-10-29 23:48:51
【问题描述】:
我有一个自定义视图,一个按钮,但 setOnClickListener() 不起作用。
class ButtonReadBarcode extends android.support.v7.widget.AppCompatButton {
public String ma_vach = "";
private Activity ac = null;
public ButtonReadBarcode(Context context) {
super(context);
ac = Global.getActivity( context);
init();
}
private void init(){
setVisibility(View.VISIBLE);
setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
setText("Scan barcode ...");
setAllCaps(false);
}
@Override
public void setOnClickListener( View.OnClickListener l) {
super.setOnClickListener(l);
// this line does now work
setText("I want this text show when click");
}
}
没有任何错误信息
【问题讨论】:
-
这能回答你的问题吗? Android button onclick override
标签: android onclicklistener android-custom-view