小编Tra*_*eIt的帖子

从另一个类调用Dialog

我是android的初学者,而不是为每个活动中的对话重复编写代码,我只是创建了一个包含显示对话框的所有方法的类,我已经给出了小代码片段

public class Dialogues extends Activity implements DialogueMethods {


    public void showAlertDialog(Context context, String title, String message) {

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
        alertDialog.setTitle(title);
        alertDialog.setMessage(message);
        alertDialog.show();
}

    //this method am calling

    public void showAlertDialog(Context context, String title, String message, String ButtonText, boolean cancel) {

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
        alertDialog.setTitle(title);
        alertDialog.setMessage(message);

        if(cancel) {

            alertDialog.setNegativeButton(ButtonText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                finish();
            }
        });
        }

        alertDialog.show();
    }

}
Run Code Online (Sandbox Code Playgroud)

我在打电话

//dialogObj is instance of the above …
Run Code Online (Sandbox Code Playgroud)

android android-dialog

4
推荐指数
1
解决办法
2647
查看次数

标签 统计

android ×1

android-dialog ×1