赞
踩
复制内容到剪贴板
代码:package com.xzw.custom.dialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
* 自定义dialog
* @author Mr.Xu
*
*/
public class MyCustomDialog extends Dialog {
//定义回调事件,用于dialog的点击事件
public interface OnCustomDialogListener{
public void back(String name);
}
private String name;
private OnCustomDialogListener customDialogListener;
EditText etName;
public MyCustomDialog(Context context,String name,OnCustomDialogListener customDialogListener) {
super(context);
this.name = name;
this.customDialogListener = customDialogListener;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
//设置标题
setTitle(name);
etName = (EditText)findViewById(R.id.edit);
Button clickBtn = (Button) findViewById(R.id.clickbtn);
clickBtn.setOnClickListener(clickListener);
}
private View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
customDialogListener.back(String.valueOf(etName.getText()));
MyCustomDialog.this.dismiss();
}
};
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。