这是我使用Sugar ORM从数据库中获取的项目,项目的索引顺序为(1,2,3,4)
删除项目索引2之后,我想使用糖Orm从头开始并按顺序(1,2,3)为3个项目开始ID。
这是我的代码
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView cup_size_index, cup_size, cup_size_type;
ImageView cupRemoveItem;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
cup_size_index = itemView.findViewById(R.id.cup_size_index);
cup_size = itemView.findViewById(R.id.cup_size);
cup_size_type = itemView.findViewById(R.id.cup_size_type);
cupRemoveItem = itemView.findViewById(R.id.cupRemoveItem);
cupRemoveItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
delRecord(getAdapterPosition());
}
});
}
}
private void delRecord(int pos) {
int delRecord = (pos + 1);
CupSize cupSize = CupSize.findById(CupSize.class,delRecord);
cupSize.setId(Long.valueOf(delRecord));
long cupId = cupSize.getId();
Toast.makeText(context, ""+cupId, Toast.LENGTH_SHORT).show();
cupSize.delete();
}
}