BT Connection - Listpicker SlectionIndex always 0

Hi all,
I am very new to the MIT App Inventor, and the first impression is great.

However, I already have a (small) problem where I did not find a solution - yes, I have been searching in the manuals and here, but I did not find the answer.

I am trying to do a Bluetooth-connection to a ESP32 - and, it basically works like a charm :grinning: After a very short time I already was able to send and display data from my ESP to the mobile. :+1:

But, I would like to show the connected device name also somewhere on the screen. Ok, I thought with the ListPicker.SelectionIndex it should not be a problem to get this information.

However, what I see, ist that - whatever I select in the ListPicker - the SelectionIndex is always 0. On my screenshot I selected Nr. 7 (ESP32), the last one in the list. Also, when I output the ListPicker.selection, I only get true instead of Addresses / Names.

Any explanation for that?

Remark: I know that for Android >10 I need the permission stuff - this works also, but for now to keep it simple I use my Android 10 device fot testing...

Thanks for any help and explanation what I am doing wrong.
Alfredo

the blocks:


the designer:

on the phone after connection to the ESP:

Don't reset the Selection in the AfterSelection event.

Just send the Connect block output to a label.

That should leave the index undisturbed.

The list of available connections is fluid, so keeping an index for long makes little sense.

Just show the selection.

BTW the connect block output is true false, check the tool tip.

What is the index in the device list for the word "true"?

1 Like

Thank you, that did help :grinning:. I just did not know that obviously the first call of the .SelectionIndex or the .Selection does reset the values.
So now I first store the Selection to the label, and in the connect block I use the label text as address, as you suggested.
And: It works!!!! :+1: Great!!


Dear @Alfredo2025, this is still wrong:


The BluetoothClient:connect returns a True/False, so you shall not overwrite the ListPicKer.Selection with that value..
It isn't the reading of the Selection or the SelectionIndex that resets the value. It is your overwriting that resets the value. And this was what @ABG was saying you.
:hugs:

EDIT: You'd probably better do like this:
image
Where, instead of a fixed address, you can still use your AddressAndNames, or your preferred mode.

3 Likes

ok, also thanks for your explanation :+1: I think now I got it :innocent:, and I even understand why it still worked with my mistake....

1 Like