我有一个列表视图,其中包含可用的蓝牙设备列表,在选择项目时,我想在该设备上连接gatt。但编译说 “BluetoothDevice类型中的方法connectGatt(Context,boolean,BluetoothGattCallback)不适用于参数(new AdapterView.OnItemClickListener(){},boolean,BluetoothGattCallback)”
这是我的代码:
ListView deviceListView = (ListView)findViewById(R.id.new_devices);
deviceListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterview, View rowView, int position, long id) {
WL.getInstance().sendActionToJS("LoadPageReceiver");
BluetoothDevice device = (BluetoothDevice)((mDevices.toArray())[position]);
Log.i(TAG, "Connecting to: " + device.getName());
//make connection
mConnectedGATT = device.connectGatt(this, true, mGattCallback);
//display progress UI
mHandler.sendMessage(Message.obtain(null, MSG_PROGRESS, "Connecting to " + device.getName() + "..."));
}}
);