简体   繁体   中英

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:

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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