我用ListView創建了一個AlertDialog。當創建AlertDialog時,它也開始掃描BLE設備。當用戶點擊其中一個項目時,scanLeDevice
函數被調用,這將停止進一步掃描。我想知道如何在AlertDialog外單擊時調用此函數?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();
}
});
請參閱:http://developer.android.com/reference/android/app/Dialog.html#setOnDismissListener(android.content.DialogInterface.OnDismissListener) –