my situation is the following:
I get a JSON-Array as response from a php script on a server after I sent a hash to it. There are two possible formations of the JSON-Array. If the hash is not valid, the first would be just like {"status":0}
. Second formation, when the hash is valid, it would have appointments in it -> would be like {"appointmentName":"Meeting","date":"2013-03-15","startTime":"10:00:00","endTime":"12:10:00","status":2}
.
The JSON-Array could be filled with more than just one appointment. See below:
{
"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
}
I want to list those appointments in a ListView on the android-app.
My method that handles the the JSON-Array:
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();
}
}
My ListView isnt something special yet:
<ListView
android:id="@+id/appointmentsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
How should it bee, that the handleActivationResult() method will fill the list with the appointments?