我正在Cloud Firestore中存储ArrayList
,其中索引是月份,值是值!像这样:
mList.add(0, 10); //where 0 is January and 10 is its correspondent value
mList.add(1, 144);
mList.add(2, 23);
//...
mList.add(11, 332);
我想更新一下2月,我通常要做的是:
mList.set(1, 100);
//since the index starts at 0,
//February would be at index 1 and the value gets changed from 144 to 100
这是我的模型课:
public class History {
private ArrayList<Integer> valuesList = new ArrayList<>(12);
public History() {}
public History(ArrayList<Integer> valuesList) {
this.valuesList = valuesList;
}
public ArrayList<Integer> getValuesList() {
return valuesList;
}
public void setValuesList(ArrayList<Integer> valuesList) {
this.valuesList = valuesList;
}
}
我知道需要使用.update(data)
,但是我不完全按照索引来更新特定值,所以问题是如何处理?