简体   繁体   English

使用通过ListAdapter或BluetoothAdapter找到的大量蓝牙设备更新Android中的TextView

[英]Update TextView in Android with amount of bluetooth devices found via ListAdapter or BluetoothAdapter

I want to create a TextView in an Android app which shows how many bluetooth devices are found and list them in the UI. 我想在Android应用程序中创建一个TextView ,显示找到多少个蓝牙设备并在UI中列出它们。

Inside the MainActivity (only acivity), there is an ArrayList inside a private class ListAdapter extends BaseAdapter . MainActivity内部(仅限acivity),私有类中有一个ArrayList ListAdapter extends BaseAdapter Besides in that class there is also a private BluetoothAdapter.LeScanCallback with onLeScan method that includes ListAdapter.notifyDataSetChanged() . 除了该类之外,还有一个带有onLeScan方法的私有BluetoothAdapter.LeScanCallback ,其中包括ListAdapter.notifyDataSetChanged() The ListAdapter uses a listView to bind the results of bluetooth scanning to the UI. ListAdapter使用listView将蓝牙扫描的结果绑定到UI。 The issue now is that I don't know how to create a trigger that sends the currently found/displayed (and constantly changing) amount of devices in a simple TextView above (!) the ArrayList and updates it every time the amount of devices in the list varies. 现在的问题是,我不知道如何创建一个发送设备的当前发现/显示(和不断变化)量的简单触发TextView以上(!)的ArrayList ,并在每一次更新IT设备的数量名单各不相同。

Do you have any suggestions? 你有什么建议吗? I have only found examples from different cases, and mostly with updating through buttons. 我只找到了不同情况下的例子,主要是通过按钮更新。

You should crate an listener for when a new Bluetooth scan is done. 您应该为新的蓝牙扫描完成时listener一个listener器。 That listener should update the UI , TextView . listener应该更新UITextView Read more about Android Callbacks here. 在此处阅读有关Android回调的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Xamarin.android 中的 BluetoothAdapter 执行蓝牙扫描 - Perform a bluetooth scan with BluetoothAdapter in Xamarin.android Android:在ListAdapter中设置TextView的可见性 - Android: Set Visibility of TextView in ListAdapter Android +通过蓝牙配对设备 - Android + Pair devices via bluetooth programmatically Android:逐个通过蓝牙连接设备 - Android: connect to devices via Bluetooth one by one Android-ClassCastException-BluetoothManager无法强制转换为android.bluetooth.BluetoothAdapter错误 - Android - ClassCastException - BluetoothManager cannot be cast to android.bluetooth.BluetoothAdapter Error 为什么 android.bluetooth.BluetoothAdapter#listenUsingL2capOn(int) 无法访问? - Why is android.bluetooth.BluetoothAdapter#listenUsingL2capOn(int) not accessible? Android,自定义 ListAdapter 获取 TextView-Text - Android, Custom ListAdapter get TextView-Text Android:使用ListAdapter从TextView获取特定文本 - Android: Getting a specific text from a TextView with a ListAdapter java.lang.NoSuchMethodError: android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser - java.lang.NoSuchMethodError: android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser 是否可以让3个或更多Android设备通过蓝牙进行三角测量? - Is it possible to get 3 or more android devices to triangulate with each other via bluetooth?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM