怎么在搜索蓝牙4.0 设备中调用蓝牙2.0的搜索界面?(和UI关系更大,和蓝牙4.0关系不大)
2017-01-03 05:14
525 查看
你好!
本人主要是做个界面:上栏是新搜索的蓝牙4.0设备,下栏是已经配对的蓝牙4.0设备,下面还有个按钮可以手动搜索,
这个界面在2.0很多,但是蓝牙4.0在adatper里面是没有配对设备的记录的,是不是能用preference来记录?
因为我看很多demo里面都是一行一行的textview,然后程序里面使用ViewHolder来加载这些textview的(textview在xml里面写好了),要做到上面的界面,是2个ListView加一个Button,我不知道怎么在ViewHolder来调用ListView,只是知道ViewHolder是为了能加快调用界面,来加快显示搜索到的蓝牙设备。
比如,现在一般用textview的xml是这么写的:
我想做的界面的xml是这样写的:
蓝牙2.0调用上面这个界面一般是这么调用的:
现在ViewHolder是这么调用的:
其实我就是想在蓝牙4.0能调用这个界面就可以了
<
4000
br />
demo里面的搜索蓝牙4.0的界面一般是这样的:
这样一条的,没有已经配对的设备,还有一个按钮的
本人主要是做个界面:上栏是新搜索的蓝牙4.0设备,下栏是已经配对的蓝牙4.0设备,下面还有个按钮可以手动搜索,
这个界面在2.0很多,但是蓝牙4.0在adatper里面是没有配对设备的记录的,是不是能用preference来记录?
因为我看很多demo里面都是一行一行的textview,然后程序里面使用ViewHolder来加载这些textview的(textview在xml里面写好了),要做到上面的界面,是2个ListView加一个Button,我不知道怎么在ViewHolder来调用ListView,只是知道ViewHolder是为了能加快调用界面,来加快显示搜索到的蓝牙设备。
比如,现在一般用textview的xml是这么写的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/device_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="24dp"/> <TextView android:id="@+id/device_address" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="12dp"/> <TextView android:id="@+id/device_uuid" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="12dp"/> </LinearLayout>
我想做的界面的xml是这样写的:
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/newDevice"/> <ListView android:id="@+id/newDevices" android:layout_width="match_parent" android:layout_height="wrap_content" android:stackFromBottom="true" android:layout_weight="2"> </ListView> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/pairedDevice"/> <ListView android:id="@+id/pairedDevices" android:layout_width="match_parent" android:layout_height="wrap_content" android:stackFromBottom="true" android:layout_weight="2"> </ListView> <Button android:id="@+id/scanButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/scanNew"/>
蓝牙2.0调用上面这个界面一般是这么调用的:
super.onCreate(savedInstanceState); // Setup the window requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.device_list); bluetooth = BluetoothAdapter.getDefaultAdapter(); // Get a set of currently paired devices Set<BluetoothDevice> pairedDevices = bluetooth.getBondedDevices(); scanButton = (Button)findViewById(R.id.scanButton); scanButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { doDiscovery(); v.setVisibility(View.GONE); } }); newDevicesList = (ListView)findViewById(R.id.newDevices); newDevicesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, newDevices); newDevicesList.setAdapter(newDevicesAdapter); newDevicesList.setOnItemClickListener(mNewDeviceClickListener); // Find and set up the ListView for paired devices pairedDevicesList = (ListView)findViewById(R.id.pairedDevices); pairedDevicesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); pairedDevicesList.setAdapter(pairedDevicesAdapter); //当点击时,启动线程connect pairedDevicesList.setOnItemClickListener(mDeviceClickListener); // Register for broadcasts when a device is discovered IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); this.registerReceiver(mReceiver, filter); // Register for broadcasts when discovery has finished filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); this.registerReceiver(mReceiver, filter);
现在ViewHolder是这么调用的:
public View getView(int i, View view, ViewGroup viewGroup) { ViewHolder viewHolder; // General ListView optimization code. if (view == null) { view = mInflator.inflate(R.layout.list_item_device, null); viewHolder = new ViewHolder(); viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address); viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name); viewHolder.deviceUuid = (TextView) view.findViewById(R.id.device_uuid); view.setTag(viewHolder); } else { viewHolder = (ViewHolder) view.getTag(); } BluetoothDevice device = mLeDevices.get(i); final String deviceName = device.getName(); if (deviceName != null && deviceName.length() > 0) viewHolder.deviceName.setText(deviceName); else viewHolder.deviceName.setText(R.string.unknown_device); viewHolder.deviceAddress.setText(device.getAddress()); try{ //Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null); ParcelUuid[] uuids = (ParcelUuid[]) device.getUuids(); String uuidStr=""; for (ParcelUuid uuid: uuids) { uuidStr = uuid.getUuid().toString()+"\n"; Log.d("Log", "UUID: " + uuid.getUuid().toString()); } viewHolder.deviceUuid.setText(uuidStr); }catch(Exception e){ put(e.toString(),"mybleYYYError"); } return view; } static class ViewHolder { TextView deviceName; TextView deviceAddress; TextView deviceUuid; }
其实我就是想在蓝牙4.0能调用这个界面就可以了
<
4000
br />
demo里面的搜索蓝牙4.0的界面一般是这样的:
这样一条的,没有已经配对的设备,还有一个按钮的
相关文章推荐
- android搜索蓝牙时,区分所搜索到的设备是2.0还是BLE
- 怎么进入UI Jazz Google新的搜索界面?
- 使用J2ME搜索蓝牙设备,并与搜到的设备通信
- 智能客户端应用学习系列:SmartClient Software factory中的Composite UI Application Block(Cab)技术了解(十):异步调用,离线处理,队列管理的关系
- 如何修改蓝牙搜索设备的时间
- ALSA驱动、设备函数调用关系
- 基于visual c++之windows核心编程代码分析(56)使用winsock搜索蓝牙设备
- Microsoft.Web.UI.WebControls怎么设置啊,装了也不行,界面不显示
- 蓝牙通信-搜索附近的蓝牙设备
- 基于visual c++之windows核心编程代码分析(56)使用winsock搜索蓝牙设备
- 基于visual c++之windows核心编程代码分析(56)使用winsock搜索蓝牙设备
- 千万别在UI线程上调用Control.Invoke和Control.BeginInvoke,因为这些是依然阻塞UI线程的,造成界面的假死
- WINCE APP之搜索蓝牙设备
- win7 x64 后蓝牙u盘搜索不到其他设备
- 应用中调用系统的搜索UI,Android Search Framework的初步了解
- 使用J2ME搜索蓝牙设备,并与搜到的设备通信
- Google新的搜索界面UI Jazz
- probe()函数是什么时候被调用,设备和驱动是怎么联系起来的
- 编程代码分析-使用winsock搜索蓝牙设备
- 修改蓝牙搜索设备的时间