Not defined for Parse, but you can easily create persistent identifiers from an object identifier:
public class StableNumericalIdProvider {
private int idProvider;
private final Map<String, Integer> numericalIds = new HashMap<>();
public int id(String stringId) {
Integer numericalId = numericalIds.get(stringId);
if (numericalId == null) {
numericalId = idProvider++;
numericalIds.put(stringId, numericalId);
}
return numericalId;
}
}
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<MyParseObject> mObjects;
private StableNumericalIdProvider idProvider;
@Override
public long getItemId(int position) {
return idProvider.id(mObjects.get(position).getObjectId());
}
}
(on the side of the note, do you need to implement getItemId? If your dataset does not change, you do not need to)
source
share