I am currently working on an android application displaying image into my listview using SimpleAdapter. My image is retrieved from my online server. After i retrieve the image, i tried to display the image but nothing was displayed and no error too.
Below is my code
class ListApplicant extends AsyncTask<String, String, String> {
// Before starting background thread Show Progress Dialog
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(SignUpApplicantActivity.this);
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
}
// getting All applicants from URL
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("eid", eid));
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_list_applicant,
"GET", params);
// Check your log cat for JSON response
Log.d("All applicants: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// applicants found
// Getting Array of applicants
applicant = json.getJSONArray(TAG_APPLICANTS);
// looping through All applicants
for (int i = 0; i < applicant.length(); i++) {
JSONObject c = applicant.getJSONObject(i);
// Storing each JSON item in variable
String uid = c.getString(TAG_UID);
String name = c.getString(TAG_NAME);
String overall = c.getString(TAG_OVERALL);
String apply_datetime = c.getString(TAG_APPLY_DATETIME);
// creating new HashMap
// HashMap<String, String> map = new HashMap<String,
// String>();
// IMAGE HASHMAP
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key (value)
map.put(TAG_UID, uid);
map.put(TAG_NAME, name);
map.put(TAG_OVERALL, overall);
map.put(TAG_APPLY_DATETIME, apply_datetime);
// adding HashList to ArrayList
// applicantsList.add(map);
// LISTING IMAGE TO LISTVIEW
try {
imageURL = c.getString(TAG_PHOTO);
InputStream is = (InputStream) new URL(
"http://ec2-175-41-164-218.ap-southeast-1.compute.amazonaws.com/android/images/"
+ imageURL).getContent();
d = Drawable.createFromStream(is, "src name");
} catch (Exception e) {
e.printStackTrace();
}
map.put(TAG_PHOTO, d.toString());
// adding HashList to ArrayList
applicantsList.add(map);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
// After completing background task Dismiss the progress dialog
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all applicants
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
if (applicantsList.isEmpty()) {
applicantDisplay
.setText("No applicants have signed up yet");
} else {
//Updating parsed JSON data into ListView
adapter = new SimpleAdapter(
SignUpApplicantActivity.this, applicantsList,
R.layout.list_applicant, new String[] {
TAG_UID, TAG_NAME, TAG_OVERALL,
TAG_APPLY_DATETIME, TAG_PHOTO },
new int[] { R.id.applicantUid,
R.id.applicantName,
R.id.applicantOverall,
R.id.apply_datetime, R.id.list_image });
// updating listView
setListAdapter(adapter);
}
}
});
}
}