一个字符串值,我有一个HashMap,将我选择的项目的一排从其他的HashMap每次得到的数据。在数据存储到散列表之前,我已经在arraylist中进行了检查。此检查是检查数组是否存在于数组列表中。如果是,我想更改数组中存在的itemID的数量值。目前,问题是数量从未更新或改变。更新在HashMap中
我知道这是不是做的最好办法,但可以在任何帮助我解决这个问题呢?提前致谢。
这是我的代码目前
private void listOrder(String itemValue, String itemID)
{
HashMap<String, String> map = new HashMap<String, String>();
String quantity = "1";
map.put(FOODID3, itemID);
map.put(FOODNAME3, itemValue);
map.put(FOODQUANTITY3, quantity);
boolean found = false;
if (!LIST3.isEmpty())
{
for (int i = 0; i < LIST3.size(); i++)
{
String exists = null;
exists = LIST3.get(i).get(FOODID3).toString();
if (exists.equals(itemID))
{
found=true;
String b = map.get(FOODQUANTITY3);
int quantityy = Integer.parseInt(b) +1;
String c = Integer.toString(quantityy);
System.out.println(c);
map.put(FOODQUANTITY3, c); // I can't update the value here
break;
}
}
}
if (!found)
{
LIST3.add(map);
}
LISTORDER = (ListView) findViewById(R.id.listOrder);
List3Adapter adapter = new List3Adapter(MainActivity.this, LIST3);
LISTORDER.setAdapter(adapter);
}
价值究竟是什么'LIST3'? – Savv
它的我想列表 –
@SavTheCoder对不起,没有提到它很清楚,LIST3是ArrayList> LIST3; –
user3040029