您的位置:首页 > 移动开发 > Android开发

Android获取dialog自定义布局中的控件

2015-04-17 15:40 357 查看
public class PopUpDialog extends Dialog {

Context context;
private View customView;

public PopUpDialog(Context context) {
super(context);
this.context = context;
// TODO Auto-generated constructor stub
}
public PopUpDialog(Context context, int theme){
        super(context, theme);
        this.context = context;
        LayoutInflater inflater= LayoutInflater.from(context);
        customView = inflater.inflate(R.layout.mydialog, null);
    }
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(customView);
}
@Override
public View findViewById(int id) {
// TODO Auto-generated method stub
return super.findViewById(id);
}
public View getCustomView() {
return customView;
}

}


customView = inflater.inflate(R.layout.mydialog, null);通过此语句获取view“指针”(借用C的术语),在新的Activity中实现调用自定义对话框中的控件。

PopUpDialog newDialog = new PopUpDialog(MsgReView.this, R.style.MyDialog);
newDialog.setCanceledOnTouchOutside(true);

View view = newDialog.getCustomView();
TextView text1 = (TextView)view.findViewById(R.id.textViewTotal);
text1.setText("调查人数:5");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: