0

So I have an ArrayAdapter that basically contains user-defined objects in it.

Following is the class of the objects the adapter contains:

private class BluetoothInfoContainer {

        private String name;
        private String address;
        private BluetoothDevice device;

        public BluetoothInfoContainer(String devName, String devAddress, BluetoothDevice dev)
        {
            name = devName;
            address = devAddress;
            device = dev;
        }

        public String getName()
        {
            return name;
        }

        public String getAddress()
        {
            return address;
        }

        public BluetoothDevice getDevice()
        {
            return device;
        }

    }

Following is how the objects are added to the Adapter

ArrayAdapter BTArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1);

            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                btd = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); //Get the device details

                BTArrayAdapter.add(new BluetoothInfoContainer(btd.getName(),btd.getAddress(),btd));
            }

        }
    };

Following is how I set the adapter to a ListView

ListView listBTDevices = (ListView) findViewById(R.id.listBTDevices);

listBTDevices.setAdapter(BTArrayAdapter);

Problem here is,

the ListView displays some weird name since the BTArrayAdapter here contains objects of the class BluetoothInfoContainer

So, what I was wondering was, if there was any way I could retrieve the device's name from the BTArrayAdapter using getName() method of BluetoothInfoContainer class & have my ListView display it.

Is there a way this can be done?

And before you downvote this question, please know that I have gone through the documentations of both ArrayAdapter and ListView and couldn't find anything helpful, hence I posted my question here.

Thank you for your time!!

Auro
  • 1,484
  • 3
  • 21
  • 52

0 Answers0