for (int i = 1; i <= totalfriends; i++) {
// Cast the integer into a string.
Integer j = new Integer(i);
// We need to retrieve the JSONObject but it's first
// stored in an array.
JSONArray friendarray = obj.getJSONArray(j.toString());
JSONObject friendobject = friendarray.getJSONObject(0);
fname = friendobject.getString("firstname");
lname = friendobject.getString("lastname");
uid = friendobject.getString("uid");
contactNameList.add(fname + " " + lname);
contactIdList.add(uid);
// add to arraylist
//Store the above in a data structure}
contactMenu = contactNameList.toArray(new String[contactNameList.size()]); idMenu = contactIdList.toArray(new String[contactIdList.size()]); contactAdapter = 新的 ArrayAdapter
// After store everything into datastructure, put the code
// inside run() and loop again and display the friendlist.
runOnUiThread(new Runnable() {
public void run() {
setListAdapter(contactAdapter);
// Here, loop through the data structure and setup
// the friend list.
}
});