获取对话框内的自定义view

不能直接用findViewById的方法,因为findViewById只能查找这个布局下面的Id,而自定义的对话框不在这个布局下面,所以要获取自定义的布局再用findViewById。

android.content.DialogInterface.OnClickListener ls = new android.content.DialogInterface.OnClickListener(){
LayoutInflater dialogInflater=LayoutInflater.from(OptionsToDo.this);
View layout = dialogInflater.inflate(R.layout.dialog_answer, null);
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
EditText edit = (EditText) layout.findViewById(R.id.answer_edittext);

String ans = edit.getText().toString();

}

大概像这样

posted @ 2014-02-01 00:06  ggaaooppeenngg  阅读(190)  评论(0编辑  收藏  举报