MyView层
public class MyVIew extends LinearLayout {
protected Context mContext;
private EditText editName;
private Button sousuo;
public MyVIew(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
View.inflate(mContext, R.layout.activity_myview, this);
initView();
}
private void initView() {
editName = findViewById(R.id.edit_name);
sousuo = findViewById(R.id.sousuo);
sousuo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String trim = editName.getText().toString().trim();
click.setClick(trim);
}
});
}
//定义接口回调
public interface Click {
void setClick(String name);
}
private Click click;
public void setItemClick(Click click) {
this.click = click;
}
}
来源:CSDN
作者:鵵鴉
链接:https://blog.csdn.net/weixin_45675546/article/details/103609410