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

115 views Asked by At

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?
1

There are 1 answers

5
Sergei Bubenshchikov On BEST ANSWER

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