我有按钮“+”和“ - ”的活动
当我点击“+”时,我的产品数量会更改为+1
我有价格,它从json解析。
当我点击“+”时,我需要将“price”字段转换为int并提高价格。
我怎么能这样做?
我的活动代码:
private void ParseAndDisplay(JsonValue json)
{
TextView productname = FindViewById<TextView>(Resource.Id.posttitle);
TextView content = FindViewById<TextView>(Resource.Id.postcontent);
TextView price = FindViewById<TextView>(Resource.Id.price);
TextView weight = FindViewById<TextView>(Resource.Id.weight);
ImageView imagen = FindViewById<ImageView>(Resource.Id.image1);
JsonValue firstitem = json[4];
productname.Text = firstitem["post_title"];
content.Text = firstitem["post_excerpt"];
price.Text = firstitem["price"] + " грн";
weight.Text = firstitem["weight"] + "г";
var imageBitmap2 = GetImageBitmapFromUrl(firstitem["img_url"]);
imagen.SetImageBitmap(imageBitmap2);
}
}
}
答案 0 :(得分:1)
您只需使用 int.Parse()即可。 但我想你需要十进制类型的价格。
//convert the price to decimal
var priceValue = decimal.Parse(firstitem["price"]);
//then increase the price
priceValue += 1M;
//then update the UI
price.Text = string.Format("{0:0.00} грн", priceValue);