在我的应用程序中,我必须在所有活动上使用相同的对话框,然后单击对话框上的按钮,我需要为不同的活动执行不同的操作,我为对话框保留了一个通用代码,然后如何调用不同的函数,这是我的代码:
final Dialog dialog = new Dialog(mContext,R.style.Theme_Levels);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_alert);
TextView title = (TextView)dialog.findViewById(R.id.title);
title.setText("Network Error");
TextView msg = (TextView)dialog.findViewById(R.id.msg_txt);
msg.setText("The system is down, please check after some time ");
ImageView cancel = (ImageView)dialog.findViewById(R.id.cancel);
cancel.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
TextView continue_btn = (TextView)dialog.findViewById(R.id.continue_btn);
continue_btn.setBackgroundResource(R.drawable.feedback_button_purple);
continue_btn.setText("Retry");
continue_btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//TODO perform different operation depending upon from where this function has been called
dialog.dismiss();
}
});
dialog.show();