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("取消按钮");
}
});
话不多说了直接上代码,结合代码进行讲解
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("取消按钮");
}
});
相关文章推荐
- Android布局中LayoutInflater的使用(利用代码添加xml形式的Layout布局)
- Android 中LayoutInflater的使用!
- android之LayoutInflater的获取与使用
- Android中LayoutInflater的使用
- Android中LayoutInflater的3种使用以及getSystemService的API
- 【Android开发】Android中LayoutInflater的使用
- Android开发--LayoutInflater的使用
- Android LayoutInflater的使用
- (转)Android LayoutInflater的使用
- Android高手进阶教程(五)之----Android 中LayoutInflater的使用!
- Android之自定义对话框AlertDialog.Builder+getLayoutInflater().inflate
- 5.Android LayoutInflater的使用
- Android 中LayoutInflater的使用
- android中LayoutInflater的使用
- android中LayoutInflater的用法及progressDialog的使用
- 无废话Android之listview入门,自定义的数据适配器、采用layoutInflater打气筒创建一个view对象、常用数据适配器ArrayAdapter、SimpleAdapter、使用ContentProvider(内容提供者)共享数据、短信的备份、插入一条记录到系统短信应用(3)
- Android高手进阶教程(五)之----Android 中LayoutInflater的使用!
- android中LayoutInflater的使用
- android中LayoutInflater的使用
- android使用LayoutInflater显示进度窗口的方法