/// <summary> /// /// </summary> /// <param name="inflater"></param> /// <param name="container"></param> /// <param name="savedInstanceState"></param> /// <returns></returns> public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { _parentView = inflater.Inflate(Resource.Layout.bluetooth_utils_fragment, container, false); _buttonScan = _parentView.FindViewById <Button>(Resource.Id.search_button); _buttonScan.Text = "Search"; _buttonScan.Click += delegate { // reset so spinner selectionused _bluetoothAction = BluetoothAction.GetListOfAvailableDevices; _scanStarted = true; // cancel any requests which may be in progress _activity.Bluetooth.Adapter.CancelDiscovery(); _activity.Bluetooth.Adapter.StartDiscovery(); }; _deviceFoundList = _parentView.FindViewById <ListView>(Resource.Id.device_list); _deviceFoundList.Adapter = new BluetoothDeviceArrayAdapter(_parentView.Context, Resource.Layout.row_layout, _deviceList); _deviceFoundList.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) { _bluetoothDevice = _deviceList[e.Position]; _deviceFoundList.SetSelection(e.Position); (_deviceFoundList.Adapter as BluetoothDeviceArrayAdapter).SetSelectedIndex(e.Position); Toast.MakeText(_parentView.Context, "Copied " + _bluetoothDevice.Name + " to clipboard.", ToastLength.Long).Show(); }; Button buttonOK = _parentView.FindViewById <Button>(Resource.Id.buttonOK); buttonOK.Click += delegate { var returnIntent = new Intent(); if (_bluetoothDevice != null) { returnIntent.PutExtra("BluetoothDeviceName", _bluetoothDevice.Name); returnIntent.PutExtra("BluetoothDeviceAddress", _bluetoothDevice.Address); } _buttonOkClicked.BluetoothFragmentOnOKButtonClicked(returnIntent, (int)ActivityCode.Bluetooth); return; }; _success = false; switch (_bluetoothAction) { case BluetoothAction.UnpairDevice: { _activity.Bluetooth.Device = _bluetoothDevice; _activity.Bluetooth.UnpairDevice(); } break; case BluetoothAction.GetListOfAvailableDevices: { _scanStarted = true; _activity.Bluetooth.Adapter.CancelDiscovery(); _activity.Bluetooth.Adapter.StartDiscovery(); } break; case BluetoothAction.PairDevice: { _activity.Bluetooth.Device = _bluetoothDevice; if (_activity.Bluetooth.IsDevicePaired()) { break; } _deviceList.Clear(); _deviceList.Add(_bluetoothDevice); _activity.Bluetooth.Adapter.CancelDiscovery(); _activity.Bluetooth.Device.CreateBond(); } break; } return(_parentView); }