Android Question How to know which button was clicked in AlertDialog?

mshafiee110

Active Member
Licensed User
Longtime User
Hi,
How to know which button was clicked in this sample?
 

Attachments

  • alertdialog.zip
    8.5 KB · Views: 219

DonManfred

Expert
Licensed User
Longtime User
Instead of just logging the result you should create and raise an event

B4X:
#If JAVA

import android.content.DialogInterface;
import android.app.AlertDialog;

public void txs() {

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("You Are Welcome")
        .setMessage("Txs for Inline Erel ;-)")
            .setPositiveButton("yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
               processBA.raiseEvent2(dialog, false, "alert_onclick", false, 1);
                 processBA.Log("Positive");
   
      }
        })
           
            .setNegativeButton("no", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                processBA.Log("Negative");
               processBA.raiseEvent2(dialog, false, "alert_onclick", false, 0);
            }
        });
builder.create();
builder.show();
}
#end if

Sub Alert_OnClick(value As Int)
    Log($"Alert_OnClick(${value})"$)
End Sub
 
Upvote 0

mshafiee110

Active Member
Licensed User
Longtime User
Instead of just logging the result you should create and raise an event

B4X:
#If JAVA

import android.content.DialogInterface;
import android.app.AlertDialog;

public void txs() {

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("You Are Welcome")
        .setMessage("Txs for Inline Erel ;-)")
            .setPositiveButton("yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
               processBA.raiseEvent2(dialog, false, "alert_onclick", false, 1);
                 processBA.Log("Positive");
  
      }
        })
          
            .setNegativeButton("no", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                processBA.Log("Negative");
               processBA.raiseEvent2(dialog, false, "alert_onclick", false, 0);
            }
        });
builder.create();
builder.show();
}
#end if

Sub Alert_OnClick(value As Int)
    Log($"Alert_OnClick(${value})"$)
End Sub
tnx.work fine.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Do you know how to put options in AlertBuilder, like this?
Sorry, i dont know... It should be possible with a dialog lib i wrapped. But there are still problems using lists inside the dialog.
Still did not find enough time to check the library.
 
Upvote 0
Top