Mokus
Mokus

Reputation: 10400

How can I call a function when the AlertDialog is dismissed?

I created an AlertDialog with a ListView. When the AlertDialog is created it starts also scanning for BLE devices. When the user clicks on one of the items the scanLeDevice function is called and this will stop further scanning. I would like to know how can I call this function when I click outside the AlertDialog?

public class BLEScan extends AlertDialog {
....
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

...
bleList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            BLEScan.this.scanLeDevice(false);
            selectedBluetoothDevice =(BluetoothDevice) (bleList.getItemAtPosition(i));
            BLEScan.this.dismiss();
        }
    });

Upvotes: 1

Views: 240

Answers (2)

Krupa Patel
Krupa Patel

Reputation: 3359

Try this.

You can override the onDismiss method in the DialogFragment, that is been called when the dialog gets dismissed.

Hope, This may help you!

Upvotes: 1

Gabe Sechan
Gabe Sechan

Reputation: 93569

Set an OnDismissListener via setOnDismissListener()

Upvotes: 1

Related Questions