如何从 Android 中 ArrayAdapter 的单行对象列表中提取特定对象?

How can I extract a specific object from a list of objects in a single row of an ArrayAdapter in Android?

我有一个名为 BTArrayAdapterArrayAdapter,我正在尝试向其中添加两个不同的对象,一个是 String,另一个是 BluetoothDevice在一行中。

以下是我的代码:

if (BluetoothDevice.ACTION_FOUND.equals(action)) 
{   

    BluetoothDevice btd = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    BTArrayAdapter.add( btd.getName() + btd.getAddress() + btd);
}

问题是

如何从单行中获取特定对象?

BTArrayAdapter.getItem(position) returns 单行包含 both, String & BluetoothDevice, 我怎样才能只提取来自它的 BluetooothDevice?

感谢您的宝贵时间!

你应该像这样创建 class:

class BlueToothContainer{

   public String adress;
   public String name;
   public BluetoothDevice device;

   //constructor etc..
}

那么您的适配器应该可以在 BlueToothContainers 列表上工作,感谢您将获得对象并从中仅获取设备或名称等。

BTArrayAdapter.getItem(position).device //it is BluetoothDevice

PS。当然,你的 class 应该有私有属性和吸气剂,我在例子中写了这个 class。