概念的に何かが欠けているのか、メソッドのいずれかにエラーがあるのか はわかりませんが、このアクティビティをかなり長い間デバッグしてきたので、何か大きなものを見落としているに違いありません。onCreate の最後に、ASyncTask をインスタンス化して GET からデータの ArrayList を設定し、onPostExecute で GraphView データを新しいデータでリセットします。私のonCreateは以下です:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cholestoral);
graph = (GraphView) findViewById(R.id.graph);
//dummy data for now, TODO: adjust dates to fit in graphical format
HDL_series = new LineGraphSeries<>(new DataPoint[] {
new DataPoint(0, 2),
new DataPoint(1, 1),
new DataPoint(2, 5),
new DataPoint(3, 3),
new DataPoint(4, 6),
});
HDL_series.setColor(Color.RED);
HDL_series.setTitle("HDL");
LDL_series = new LineGraphSeries<>(new DataPoint[] {
new DataPoint(0, 7),
new DataPoint(1, 8),
new DataPoint(2, 5),
new DataPoint(3, 8),
new DataPoint(4, 7),
});
LDL_series.setColor(Color.CYAN);
LDL_series.setTitle("LDL");
graph.addSeries(HDL_series);
graph.addSeries(LDL_series);
//empty arraylist on page load... to be filled in ASyncTask below
new ListCholestoralAPI().execute("http://m-health.cse.nd.edu:8000/phrService-0.0.1-SNAPSHOT/chol/chol/");
doInBackground は情報のリストを正しく入力し、アプリケーションをクラッシュさせ続けるセクションである onPostExecute に送信されます。onPostExecute は、initializeGraph() というアクティビティの関数を呼び出すだけです。
public void initializeGraph() {
//TODO: initialize graph by setting labels, axes, etc...
HDL_series.resetData(generateDataPoints());
}
public DataPoint[] generateDataPoints() {
dataPointArray = null;
dataPointArray = new DataPoint[30];
for (int i = 0; i < cholesterolInformationList.size(); i++) {
double hdl = cholesterolInformationList.get(i).getHdl();
dataPointArray[i] = new DataPoint(i, hdl);
}
//dataPointArray = sortDataPointArray(dataPointArray);
return dataPointArray;
}
注: ここで概念的に欠陥があると思われるものがあれば、お知らせください。私はかなり単純なタスクに膨大な時間を費やしました。