I am working on ShoppingList
project which holds information about amount of items and its price. The thing is that I kept them all into one array Shopping list<>. So now when I use AlertDialog
Builder and input for example:
1 pc. Banana 25 eur.
I am not able to reach price, which I need to calculate final price of the products.
AlertDialog info:
How it looks so far:
This is a code which handles price amount:
if (id == R.id.action_add)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Fill out the fields");
final EditText amount = new EditText(this);
final EditText Item = new EditText(this);
final EditText price = new EditText(this);
amount.setHint("Input amount..");
Item.setHint("Input item.. ");
price.setHint("Input price.. ");
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setOrientation(LinearLayout.VERTICAL);
amount.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
price.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
layout.addView(amount);
layout.addView(Item);
layout.addView(price);
builder.setView(layout);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
shoppingList.add(" " + amount.getText()+ " pc. " + " "+Item.getText().toString()+ " " + price.getText().toString() + " Dkk");
Collections.sort(shoppingList);
storeArrayVal(shoppingList, getApplicationContext());
lv.setAdapter(adapter);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
return true;
}
Underneath, I am trying to make and function which should summarize all inputed amounts. This is what i have so far
if (id == R.id.action_sum) {
Context context = getApplicationContext();
CharSequence text = "Total amount here";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}