自定义dialog
public class TishiDialog extends Dialog {
//用来实现对布局按钮的调用
public interface SubmitListenerInterface {
void doItemClick();
}
private TishiDialog.SubmitListenerInterface clickListenerInterface;
private String msg;
private Context context;
String title;
public TishiDialog(Context context) {
super(context);
}
public TishiDialog(Context context, int theme, String msg, String title, TishiDialog.SubmitListenerInterface clickListenerInterface) {
super(context, theme);
this.context = context;
this.msg = msg;
this.clickListenerInterface = clickListenerInterface;
this.title=title;
}
protected TishiDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//自定义的布局样式
setContentView(R.layout.dialog_tishi);
init();
}
public void init() {
TextView msgTV = (TextView) findViewById(R.id.dialog_prompt_msg);
msgTV.setText(msg);
TextView tv_title = (TextView) findViewById(R.id.dialong_tishi_title);
tv_title.setText(title);
findViewById(R.id.dialog_prompt_submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickListenerInterface.doItemClick();
dismiss();
}
});
findViewById(R.id.dialog_prompt_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
}
//在activity的调用,但是要记住要继承一下点击事件(不使用时可以重写改方法)

TishiDialog dialog = new TishiDialog(BookActivity.this, R.style.Dialog_normal,"确定删除好友吗?","提示",BookActivity.this);
dialog.show();
//在fragment的调用,但是要记住要继承一下点击事件(不使用时可以重写改方法)
TishiDialog dialog = new TishiDialog(getContext(), R.style.Dialog_normal,"确定删除聊天记录吗?","提示",MyMessageFragment.this);
dialog.show();
网友评论