I'm trying to make a user profile page.
I have done some hard work and managed to retrieve the json objects and store user data in sql database and display these data (string) into TextView such as name and email which works fine.
I also have the URLs to users photos in the same database but I can't retrieve the URL and display on the ImageView just like the other text string..
Could someone kindly show me how to tweak this code to do that?
Please consider this from a Java newbie. Thank you! ^^
public class DirectoryDetailMeActivity extends Activity {
String eid; //user ID
JSONParser jsonParser = new JSONParser();
private static final String url_veiw_directory = "http://www.myweb.com/android/include/directory_detail_me.php";
private static final String TAG_ID = "eid";
private static final String TAG_IMG = "photo";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directory_detail_me);
new GetDirectoryDetails().execute();
}
class GetDirectoryDetails extends AsyncTask<String, String, String> {
protected String doInBackground(String... params) {
runOnUiThread(new Runnable() {
public void run() {
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id", eid));
JSONObject json = jsonParser.makeHttpRequest(url_veiw_directory, "GET", params);
Log.d("my profile", json.toString());
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
JSONArray directoryObj = json.getJSONArray(TAG_DIRECTORY);
JSONObject directory = directoryObj.getJSONObject(0);
// It works fine if I give the URL manually.
String imageURL = "";
ImageView imagePhoto = (ImageView) findViewById(R.id.photo);
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(imageURL, imagePhoto);
TextView txtName = (TextView) findViewById(R.id.name);
TextView txtEmail = (TextView) findViewById(R.id.email);
txtName.setText(directory.getString(TAG_NAME));
txtEmail.setText(directory.getString(TAG_EMAIL));
}else{
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}