我想將此活動中的totalBalance保存到SharedPreferances並將其恢復到另一個類中。如何在SharedPeference中保存活動中的值並訪問所有其他類
,所以我想totalbalance被顯示在同一應用程序的另一個活動...... 如果可能的話也在其他activites編輯...
請幫助...謝謝
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
// Genrating random number Random number
Random rn = new Random();
randomNumber = (int) rn.nextInt(9) + 1;
// changes textView1 equals to random number
textView1.setText("Random Number is "
+ Integer.toString(randomNumber));
button1.setText("Play Again");
// Matching random number to ArrayList
if (positive_IDs.contains(randomNumber)) {
// if matched then changes textView2 to Matched Number
textView2.setText("Number: "
+ Integer.toString(randomNumber) + " Matched");
totalBalance = totalBalance + winingPrize;
textView5.setText("Total Balance = Rs: "
+ String.format("%.2f", totalBalance));
}
}
你getYourValue是有缺陷的,它總是分鐘的價值。 – RvdK
@RvdK現在我編輯了 –