动态添加控件的使用

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) {

}

}

posted @ 2015-01-04 11:32  Wang_Daxiong  阅读(272)  评论(0编辑  收藏  举报