I have an arraylist that is filled with objects from a bluetooth scanner and I show it in a recycler. What I want to do is if there is one that does not add it and only replace its value.
This object brings the distance by moving it, I am receiving a new one, so I need to modify the distance value only without adding it again.
for( int i =0; i < datos.size() ; i++ ){
if (!datos.contains(beaconModel))
{
datos.add(beaconModel);
adapter = new BeaconAdapter(datos, RangingActivity.this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
Log.d("datos", datos.toString());
datos.set(i,beaconModel);
}
else if (datos.contains(beaconModel)){
datos.set(i,beaconModel);
adapter = new BeaconAdapter(datos, RangingActivity.this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
Log.d("datos", datos.toString());
}
}
With this I have been able to update the data but it adds it a thousand times xD.
BeaconModel
is the object.
datos
is the arraylist that contains those objects.