About the ArrayList add function

Asked 2 years ago, Updated 2 years ago, 116 views

    List<String> listItems = new ArrayList<String>();
    for(BluetoothDevice device : mDevices) {
           listItems.add(device:mDevices){
        }
        listItems.add ("Cancel");
    }
        final CharSequence[] items = listItems.toArray(new CharSequence[listItems.size()]);

        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (item == mPairedDeviceCount) {

                } } else {

                }
            }
        });

I'm trying to use Bluetooth API to connect to Arduino I want to get a list of Bluetooth devices and pair them. Error in list.add (device:mDevices). The error content is ';' expected, '' expected untoken There's an error. What's the problem here?

arraylist add

2022-09-21 14:35

1 Answers

http://hyoin1223.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EB%B8%94%EB%A3%A8%ED%88%AC%EC%8A%A4-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D

I think you reported it on this blog, as far as I know

list.add(a : b) {}

This grammar doesn't exist.

Maybe the blogger made a typo.

// Create a list of names for paired Bluetooth devices
List<String> listItems = new ArrayList<String>();
for (BluetoothDevice device : mDevices) {
    listItems.add(device);
}
listItems.add("Cancel"); // Add Cancel Item 

Do it like this.


2022-09-21 14:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.