1

私は GraphView ライブラリを使用しています。SharedPreferences onStop() に保存される ArrayList に格納されたデータがあります。グラフを描画するインテント/クラスが呼び出されると、以前に保存されたデータを SharedPreferences から読み取り、グラフの描画に使用される配列に保存します。

しかし、グラフは次のようになります: http://i.stack.imgur.com/12j5j.jpg

ArrayList に追加された唯一のデータは 14 です。すでに配列リストについて調査したところ、最初の容量は 10 であることがわかりました。たぶんそれが問題ですか?

メイン アクティビティで ArrayList を復元するコード:

SharedPreferences arrayGraph = getSharedPreferences("arrayGraph_temp_1", 0);
int arraySize = arrayGraph.getInt("arrayGraph_temp_1_size", 0);

for (int i = 0; i < arraySize; i++) {

    float temp = arrayGraph.getFloat("temp_" + i, 0);
    arrayGraph_temp_1.add(i, temp);
}

float 変数を ArrayList に追加するコード:

arrayGraph_temp_1.add(arraySize, x);

ArrayList を SharedPreferences に保存するコード:

SharedPreferences arrayGraph = getSharedPreferences("arrayGraph_temp_1", 0);  
SharedPreferences.Editor editor = arrayGraph.edit();                          

int listSize = arrayGraph_temp_1.size();
editor.putInt("arrayGraph_temp_1_size", listSize);

for (int i = 0; i < listSize; i++) {

    float temp = arrayGraph_temp_1.get(i);
    editor.putFloat("temp_" + i, temp);
}

editor.commit();

クラス内のデータを復元してグラフを描画するコード:

SharedPreferences arrayGraph = getSharedPreferences("arrayGraph_temp_1", 0);
int arraySize = arrayGraph.getInt("arrayGraph_temp_1_size", 0);

GraphView.GraphViewData[] data;
data = new GraphView.GraphViewData[arraySize];

for (int i = 0; i < arraySize; i++) {

    float temp = arrayGraph.getFloat("temp_" + i, 0);
    data[i] = new GraphView.GraphViewData(i, temp);

}

何か案は?

4

0 に答える 0