Categories
Android

Android 获得Dialog中的数据

LayoutInflater layoutInflater = getLayoutInflater();
final View dialogView = layoutInflater.inflate(R.id.dialog);

然后在Dialog的设置按钮的onClick()方法中写入:

TextView text = (EditText)dialogView.findViewById(R.id.username_edit); //注意findViewById前面有特定的View
String textContent = text.getText().toString();
outView.setText(textContent); //outView就是需要写入数值的控件

LayoutInflater inflater =(LayoutInflater)getApplicationContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.course_custom_dialog, null);
AlertDialog.Builder builder2=new AlertDialog.Builder(MainDialogActivity.this);
builder2.setView(view);
builder2.setTitle(“添加课程”)
.setPositiveButton(“保存”, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}

})
.setNegativeButton(“取消”, null)
.create().show();

两段代码来自网络

http://blog.csdn.net/starrexstar/article/details/7868324

http://my.oschina.net/laiwanshan/blog/99481

Leave a Reply

Your email address will not be published. Required fields are marked *