我与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);
}
}
最简单的方法是将SharedPreferences.Editor API与put API集结合使用:
//update application settings based on check box state
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activityContext);
Editor editor = sharedPrefs.edit();
editor.putBoolean("optionName", !checkBox.isChecked());
editor.commit();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句