方法一:
在Activity中直接使用:
private Context context;
LayoutInflater factory = LayoutInflater.from(context);
View dialog = factory.inflate(R.layout.dialog, null); //dialog的布局
TextView tv = (TextView) dialog.findViewById(R.id.textview1); //注意用dialog.findViewById();
tv.setText("111"); //修改dialog布局中的信息
AlertDialog.Builder text = new AlertDialog.Builder(context);
text.setTitle("客户详细信息");
text.setView(dialog);
text.setPositiveButton("确定",new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
//添加确定后的操作
}
});
text.setNegativeButton("取消",null);
//AlerDialog.Builder才有确定、取消。
//虽然可以在自定义的dialog中使用Button ,但考虑整体效果还是使用setPositiveButton
text.show();
方法二:
1、自定义一个类,继承Dialog
<span style="white-space:pre"> </span>class CustomDialog extends Dialog {
public CustomDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_feidan);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
//按钮的操作
}
});
}
//called when this dialog is dismissed
protected void onStop() {
Log.d("TAG","+++++++++++++++++++++++++++");
}
<span style="white-space:pre"> </span>}
2、Activity中使用
<span style="white-space:pre"> </span>CustomDialog cd = new CustomDialog(context);
cd.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉dialog的标题
cd.show(); </span>