ユーザープロフィールページを作ろうとしています。
私はいくつかのハードワークを行い、jsonオブジェクトを取得してユーザーデータをsqlデータベースに保存し、これらのデータ(文字列)を名前や電子メールなどのTextViewに表示することができました。
同じデータベースにユーザーの写真への URL もありますが、他のテキスト文字列と同じように、URL を取得して ImageView に表示することはできません。
誰かがこのコードを微調整してそれを行う方法を教えてもらえますか?
Java初心者からこれを考慮してください。ありがとうございました!^^
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();
}
}
}