我如何打电话"警报对话"在继承的类中

时间:2015-06-24 15:32:16

标签: android

我有一个在PrepaidBase中声明的警告对话框,它有两个方法alertDialogShow()和call()。单击"是"时调用call()方法;警告对话框的按钮和alertDialogShow()方法调用激活布局的按钮。

PrepaidBase

public class PrepaidBase extends Activity {


private String number = "";

public void alertDialogShow(Context context, String title, String message, String _number) {

    this.number = _number;

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.setCancelable(false);

    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            call();
        }
    });


    builder.setNegativeButton("No", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            dialog.cancel();
        }
    });


}

public void call()
{
    Intent in = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode(number)));
    try
    {
        startActivity(in);
        alertDialogShow(this, "Some Test", "Text Here too", "*1234#");
    }catch (ActivityNotFoundException e)
    {
        e.printStackTrace();
    }
}

现在这个类继承自PrepaidBase类

public class PrepaidLBO extends PrepaidBase {

Button chobeesButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chobeesghantay);

   chobeesButton = (Button)findViewById(R.id.chobeesButton);


    chobeesButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //alertDialogShow(PrepaidLBO.this, "Some Test", "Text Here too", "*1234#");
            call();
        }
    });


}

问题是

我想在点击chobeesButton时调用alertDialogMethod()。单击警告对话框的正按钮时调用Call()方法。

1 个答案:

答案 0 :(得分:1)

您的两个问题几乎相同,我已经为您提供了答案HERE