0
votes

I am created one table For example Product name Product price product quantity Product Id. I want to pass id argument Product Id and get all value Product price .How to calculate all Product price in total amount.Give me some query. and also if i have to change product quantity means multiply to Product price amount automatically in text view .I have used custom list view i have insert all data don't know this scenario .

For Example

Screen UI

Productname Productprice Productquantity productid

Meals 345 Edittext 3 3454

Egg 32 4 2323

Briyani 223 2 2365

2

2 Answers

1
votes

I want to pass id argument Product Id and get all value Product price .How to calculate all Product price in total amount.

You need to use SUM() function for calculating prices and that all what you need:

String query = "select SUM(price) from Product where product_id = ?";
Cursor c = db.rawQuery(query, new String[] {"someValue"});
double sum;
if (c.moveToFirst()) {
   sum = c.getDouble(0);
}

How to calculate all Product price in total amount.

String query = "select SUM(price) from Product";
Cursor c = db.rawQuery(query, null);
double total;
if (c.moveToFirst()) {
   total = c.getDouble(0);
}
0
votes

You have to modify Your sum = c.getDouble(c.getColumnCount());

best luck