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

Android中利用LayoutInflater使用Dialog

2010-11-20 20:25 357 查看
我们在使用Dialog的时候,可以自己定义布局, 但是得利用LayoutInflater进行调用。

话不多说了直接上代码,结合代码进行讲解

LayoutInflater inflater = LayoutInflater.from(this);

final View textEntryView = inflater.inflate(R.layout.dialog_text_entry,
null);
final EditText username;
final EditText password;

username = (EditText) textEntryView.findViewById(R.id.user_name_edit);
password = (EditText) textEntryView.findViewById(R.id.password_edit);

AlertDialog.Builder dialog = new AlertDialog.Builder(context);

dialog.setIcon(R.drawable.icon);
dialog.setTitle("标题");
dialog.setView(textEntryView);
dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int btn) {
if (btn == AlertDialog.BUTTON_POSITIVE) {
if (username.getText().toString().equalsIgnoreCase("a")) {
setTitle("OK1");
} else {
setTitle("No1");
}
} else {
}

}

private CharSequence getText(int user_name_edit) {
// TODO Auto-generated method stub
return null;
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int btn) {
// do it if click the button 取消
// setTitle("取消按钮");
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: