【发布时间】:2014-06-14 03:20:54
【问题描述】:
我在与 B 运行计算后共享了偏好值 A,您可以通过将 A 替换为新值直接将 AB 的结果写入共享偏好中
public class Stats extends Activity {
private final static String MY_PREFERENCES = "MyPref";
private final static String GIORNISPETT = "giornispett";
public void indietro (View view){
}
@Override
public void onCreate(Bundle savedInstanceState) {
SharedPreferences prefs = getSharedPreferences(MY_PREFERENCES, Context.MODE_PRIVATE);
int giornispett = Integer.parseInt(prefs.getString(GIORNISPETT, "24"));
super.onCreate(savedInstanceState);
setContentView(R.layout.stats);
Intent intent=getIntent();
String trn=getPackageName();
int Giorni=intent.getIntExtra(trn+".Intgiorni", 0);
int Giorniresidui=giornispett-Giorni;
TextView tvgiorni=(TextView)findViewById(R.id.txtgiorni);
tvgiorni.append(+Giorni+"");
TextView tvGiorni_rest=(TextView)findViewById(R.id.txtGiorni_rest);
tvGiorni_rest.setText(""+Giorniresidue);
}
}
【问题讨论】:
-
已经有多个问题在问这个问题,一个简单的谷歌就会返回许多基本示例和教程。请在发布新问题之前进行一些研究。