简体   繁体   English

Android蓝牙:动态更新列表视图中单行的连接状态

[英]Android Bluetooth: Update connection state dynamically for single row in listview

I would like to create a listview with all bluetooth devices scanned. 我想创建一个扫描了所有蓝牙设备的列表视图。 Each row will contain a connection state of text and clicking it will make the device connect to remote device. 每行将包含文本的连接状态,单击该行将使设备连接到远程设备。 How could I update only the single row of remote device being connected in listview so the connection state will keep changing: disconnected -> connecting -> connected for example? 我如何只更新列表视图中正在连接的远程设备的单行,以便连接状态将不断变化:例如,断开连接->连接->已连接?

  1. Update single row only so the row object needs to be passed to updater somehow? 仅更新单行,因此需要以某种方式将行对象传递给更新程序?
  2. State needs to keep changing so I need to create a customized listener? 状态需要不断变化,所以我需要创建自定义的侦听器吗?

You can take row from ListView at required position and update: 您可以在所需位置从ListView中获取行并进行更新:

private void refreshConnectionState(int rowIndex, String newConnectionState){
    View row = devicesListView.getChildAt(rowIndex);
    if(row == null) return;

    TextView stateTextView = (TextView )row.findViewById(R.id.state_text_view);       
    stateTextView.setText(newConnectionState);
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM