首先對不起我的英語是一件壞事。 現在我正在編寫一個應用程序,並且列表中存在問題。 我總是在我的名單重複搜索設備後,當我再次搜索,我再次得到相同的設備。我必須嘗試使用套,但我仍然重複。 我不知道如何解決這個問題。 請用代碼幫助別人。 謝謝提前。重複在ListView藍牙
這裏是我的代碼:
`
public void Init(){
foundDevicesSet = new HashSet<String>();
tBtn = (ToggleButton)findViewById(R.id.toggleButton1);
availableDivce = (TextView)findViewById(R.id.textView2);
bluetoohOff =(TextView)findViewById(R.id.textView1);
DeviceList = (ListView)findViewById(R.id.listView1);
searchButton =(Button)findViewById(R.id.button1);
deviceNameAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1);
DeviceList.setAdapter(deviceNameAdapter);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(receiver, filter);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice newDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (newDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
foundDevicesSet.add(newDevice.getName() + "|" + newDevice.getAddress());
for(String one : foundDevicesSet){
deviceNameAdapter.add(one);
}
}
}
}
};
} `
不是一個真正的通用解決方案,但+1,很好的答案 – avalancha