I am fairly new to android development and i have a dilemma. I want to pass a float from another activity that is in shared preferences and add it to the total.
Basically, what i want to do is:
- Get the values from Split Activity and pass it to the Main Activity
- total += passed value
- display the total
- save it in shared preferences
And what i have now:
- Get the values from Split Activity and pass it to the Main Activity
- it doesn't add in total
- Displays only the passed value. not the total
I have tried implementing a float Total = 0;
then add the passed valued: Total += passed value
But when i display it, it only displays the passed value
All i get is the values are not adding. Which they should. Please enlighten me on this. here are my codes:
Display Bill(Main Activity):
public void DisplayBill(){
//Retrive Shared Preferences
SharedPreferences Billing = getApplicationContext().getSharedPreferences("Bill", MODE_PRIVATE);
float Total = Billing.getFloat("Bill", 0);
final TickerView tickerView = (TickerView) findViewById(R.id.ticker_bill);
tickerView.setCharacterList(TickerUtils.getDefaultNumberList());
tickerView.setCharacterList(TickerUtils.getDefaultListForUSCurrency());
tickerView.setText("$".concat(String.valueOf(Total)));
}
Split Bill(Split Activity):
public void Compute(){
//SHARED PREFERENCE
SharedPreferences Billing = getApplicationContext().getSharedPreferences("Bill", MODE_PRIVATE);
//CES TICKER
final TickerView tickerCes = (TickerView) findViewById(R.id.tickerCes);
tickerCes.setCharacterList(TickerUtils.getDefaultNumberList());
tickerCes.setCharacterList(TickerUtils.getDefaultListForUSCurrency());
//MON TICKER
final TickerView tickerMon = (TickerView) findViewById(R.id.tickerMon);
tickerMon.setCharacterList(TickerUtils.getDefaultNumberList());
tickerMon.setCharacterList(TickerUtils.getDefaultListForUSCurrency());
EditText edtBill = (EditText) findViewById(R.id.et_bill);
float Bill = Float.parseFloat(edtBill.getText().toString());
float SplitBill;
SplitBill = (Bill/2);
tickerCes.setText("$".concat(String.valueOf(SplitBill)));
tickerMon.setText("$".concat(String.valueOf(SplitBill)));
//Set Shared Preferences
SharedPreferences.Editor editor = Billing.edit();
editor.putFloat("Bill",Bill);
editor.commit();
}