我想组合多个订单项行以获得单行。像这样List<Cart> carts = db.getAllCarts();
for (Cart cart : carts) {
Map<String, String> order = new HashMap<>();
order.put(cart.getItemCode(), cart.getQty() + "," + cart.getDescription() + ",");
Log.d("ord", String.valueOf(order));
}
当我记录时,它显示超过1行。
{440059=1,Champagne,}
{440055=5,Noodle,}
{440057=2,Salad Soup,}
日志
Util.isImageSize = function (file, callback) {
var fileUpload = file;
var reader = new FileReader();
reader.readAsDataURL(fileUpload.files[0]);
reader.onload = function (e) {
var image = new Image();
image.src = e.target.result;
image.onload = function () {
var height = this.height;
callback(height);
};
}
}
答案 0 :(得分:1)
使用以下一个
替换每个循环for(int i=0;i<carts.size();i++){
java.util.Map<String, String> order = new java.util.HashMap<>();
String desc = carts.get(i).getDescription();
if(i != carts.size()-1)
{
desc = desc + ",";
}
order.put(carts.get(i).getItemCode(), carts.get(i).getQty() + "," + desc);
}
答案 1 :(得分:0)
您可以改为使用TextUtils.join:
List<Cart> carts = db.getAllCarts();
String result;
for (Cart cart : carts) {
Map<String, String> order = new HashMap<>();
result = TextUtils.join(", ", carts );
}
Log.d("ord", result);