[英]How to update data in a List<? extends Map<String,?>>
I'm making use of a List<? extends Map<String,?>>
我正在使用List<? extends Map<String,?>>
List<? extends Map<String,?>>
that I populated with data. List<? extends Map<String,?>>
了我用数据填充的List<? extends Map<String,?>>
。
cursor.moveToFirst();
while (cursor.getPosition() < cursor.getCount()) {
item.put("ProdName",cursor.getString(2));
item.put("ProdSize", cursor.getString(3));
item.put("ProdPack",cursor.getString(4));
item.put("OrdQty","0");
//list.add(item);
list.add(i, item);
item = new HashMap<String,String>();
cursor.moveToNext();
i = i + 1;
}
How do I update a value for example in the OrdQty
field? 如何更新例如OrdQty
字段中的值?
Looks like a very bad design to me. 在我看来,这是一个非常糟糕的设计。 Java's an object-oriented language. Java是一种面向对象的语言。 Why don't you provide a real contract and create Product and Order objects? 您为什么不提供真实的合同并创建产品和订单对象? Give Order a List of Products to maintain. 给订单提供要维护的产品清单。 What you're proposing is less self-explanatory and harder to write and maintain. 您提出的建议不那么自解释,更难编写和维护。
@Duffymo is right, you shouldn't use a map as a pseudo-object. @Duffymo是正确的,您不应该将地图用作伪对象。
This is how to update an object at a specific place ( index
) in a list. 这是在列表中特定位置( index
)更新对象的方法。
Map<String,?> ugly = list.get(index);
Then you can do whatever you want with the object ugly. 然后,您可以对对象进行丑陋的处理。
If you did it properly, it would look like this... 如果做得正确,它将看起来像这样...
Product p = list.get(index);
p.setOrderQuantity(17);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.