SharedPreference类:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//about 30 Strings
String w1 = prefs.getString("w1", "");
String w2 = prefs.getString("w2", "");
String w3 = prefs.getString("w3", "");
String w4 = prefs.getString("w4", "");
String w5 = prefs.getString("w5", "");
String w6 = prefs.getString("w6", "");
//Convert to decimal numbers here
//Set up an Array list containing all these numbers here
}
我们想要检索数组列表的Activity的一部分:
private LineData generateLineData() {
//Call SharedPreferences here
SharedPreferences shared = getSharedPreferences("Prefs", MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
Call Array list here
LineData d = new LineData();
//Replace or introduce our Array list instead of "entries"
ArrayList<Entry> entries = new ArrayList<Entry>();
for (int index =0 ; index < itemcount; index++)
entries.add(new Entry(getRandom(15, 10), index));
LineDataSet set = new LineDataSet(entries, "first series");
答案 0 :(得分:1)
你可以通过循环完成所有这些。
ArrayList<Double> listOfNumbers = new ArrayList<Double>();
for (int i = 1; i <= NUMBER_OF_STRINGS; i++) {
listOfNumbers.add(Double.parseDouble(prefs.getString("w" + i, "0")));
}
如果您确定所有值都是双倍的话,这只会起作用,否则您必须检查以确保Double.parseDouble
方法不会抛出NumberFormatException