Reading users choice in dialog

Is it possible to read users action in the dialog?

Example: On button bttn1 click, dialog opens. If user clicks No in the dialog, nothing happens. If user clicks Yes, then bttn1 becomes unavailable and bttn2 changes its state from setEnabled(false) to setEnabled(true).

General question but I am partially reffering to Bluetooth setup documentation where startActivityForResult() is used.

As current answer provides, it is about using startActivityForResult() and onActivityResult() but I still have no idea how to implement this in such condition.

I am not able to implement this to overcome such problem.

Answers


Not sure if this is what you want, but you can create a dialog and listen to positive and negative button clicks.

new AlertDialog.Builder(this)
.setMessage("Deny or Grant?")
.setNegativeButton("Deny", new DialogInterface.OnClickListener() {    

    @Override
    public void onClick(DialogInterface arg0, int arg1) {
        // Do something on deny click.
    }
})
.setPositiveButton("Grant", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface arg0, int arg1) {
        // Do something on grant click.    
    }
})
.create().show();

EDIT:

To detect if the user has granted or denied bluetooth permission, you should override onActivityResult in your activity and check the resultCode. From the documentation:

A dialog will be displayed, requesting user permission to make the device discoverable, as shown in Figure 2. If the user responds "Yes," then the device will become discoverable for the specified amount of time. Your activity will then receive a call to the onActivityResult()) callback, with the result code equal to the duration that the device is discoverable. If the user responded "No" or if an error occurred, the result code will be RESULT_CANCELED.


Need Your Help

Dynamic URL for Service Reference in visual Studio 2010

wcf sharepoint visual-studio-2010

I am writing a Silverlight 3 application, this app uses a service reference to connect to a SharePoint site by using Sharepoint Lists.asmx web service

Newbie question regarding submatrix manipulation using BOOST uBLAS

c++ matlab boost ublas

This has been puzzling me for a few hours, so maybe someone here can help. I am trying to translate the following simple Matlab program into C++ using uBLAS: