public class MyLayout extends LinearLayout implements OnClickListener {// 继承你需要的控件(通常也会需求监听点击事件)
private Model model;// 传参
private Context context;
//private MyClickListener myClickListener;
public MyLayout(Context context, Model model) {// 构造
super(context);
this.context = context;
this.model = model;
inflate(context, R.layout.yourlayout, this);// 绑定所需要的布局
initView();
}
/**
* 初始化
*
* @param pkgModel
*/
private void initView() {
if (model != null) {
TextView tv_title = (TextView) findViewById(R.id.tv_title);
tv_title.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
}
}
时间: 2024-10-11 06:06:25