studio之自定义View搜索框

怎甘沉沦 提交于 2020-01-27 01:20:22

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;
    }


}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!