Reputation: 609
I have a list like 0,1,2,3. When I delete the number 2 from that list I get 0, 1, 3. How do I do to change the list to 0, 1, 2?
holder.closeButton.setOnClickListener(new View.OnClickListener(){
@Override public void onClick(View view){
if(ItemsListAdapter.this.onItemClickListener != null){
ItemsList.this.onItemClickListener.onItemCloseBtnClicked(itemModel);
ItemRepository.getInstance.delete(itemModel);
List<ItemEntity> items = ItemRepository.getInstance().selectAll();
if(itemModel.getIndex() > itemModel.size()){
for(ItemEntity itemEntity : items){
//
}
}
}
}
});
Upvotes: 0
Views: 146
Reputation: 609
Thank you everybody for the help. But I solved my problem doing something like this:
for(int i = 0; i < items.size(); i++){
items.get(i).setIndex(i);
ItemsRepository.getInstance().update(items.get(i));
}
Sorry if my question was not detailed
Upvotes: 0
Reputation: 170
From what I understand to your question, you just need the index number and not the element value.
Then don't even consider using the element value rather reply on the index number.
Alternatively, delete the last index.
Upvotes: 2