Awdi
Awdi

Reputation: 161

How do i call "Alert Dialog" in inherited class

I have a alert dialog which is declared in PrepaidBase which have two methods alertDialogShow() and call(). That call() method call when click on "Yes" button of alert dialog and alertDialogShow() method call on Activate button of layout.

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();
    }
}

Now this class inherit from PrepaidBase class

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();
        }
    });


}

Issue is

I want to call alertDialogMethod() on clicking on chobeesButton. and Call() method is called when click on positive button of alert dialog.

Upvotes: 0

Views: 309

Answers (1)

user1014191
user1014191

Reputation:

Your both questions are almost same i already provided you the answer HERE

Upvotes: 1

Related Questions