私の状況は次のとおりです。サーバーにハッシュを送信した後、サーバー上のphpスクリプトから応答としてJSON配列を取得します。JSON配列には2つの可能な形式があります。ハッシュが有効でない場合、最初のハッシュはのようになり{"status":0}
ます。2番目のフォーメーション、ハッシュが有効な場合、ハッシュには予定が含まれます->はのようになります{"appointmentName":"Meeting","date":"2013-03-15","startTime":"10:00:00","endTime":"12:10:00","status":2}
。
JSON配列は、複数の予定で埋められる可能性があります。下記参照:
{
"appointmentName": "Proposal",
"date": "2013-11-11",
"startTime": "09:00:00",
"endTime": "13:00:00",
"status": 2
}
{
"appointmentName": "Meeting",
"date": "2013-03-15",
"startTime": "10:00:00",
"endTime": "12:10:00",
"status": 2
}
android-appのListViewにそれらの予定をリストしたいと思います。
JSON配列を処理する私のメソッド:
public void handleActivationResult(String result) {
try {
JSONObject jsonObject = new JSONObject(new String(result));
String statusCode = jsonObject.getString("status");
TextView mainView = (TextView) findViewById(R.id.textView1);
if (statusCode.equals("2")) {
//fill listview with appointments
} else if (statusCode.equals(0)) {
//empty string sent to server
} else if (statusCode.equals(5)) {
//hash doesnt match
} else if (statusCode.equals(6)) {
//correct hash, but no upcoming appointments
} else {
//unknown error
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
私のListViewはまだ特別なものではありません:
<ListView
android:id="@+id/appointmentsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
handleActivationResult()メソッドがリストに予定を入力するのはどうでしょうか。