2012-11-16 5 views
0

사용자 프로필 페이지를 만들려고합니다.DB에서 URL 이미지를 ImageView에 표시하는 방법

저는 열심히했는데 json 개체를 검색하고 사용자 데이터를 SQL 데이터베이스에 저장하고 이러한 데이터 (문자열)를 이름과 이메일 같은 TextView에 표시합니다.

는 또한 동일한 데이터베이스에있는 사용자의 사진에 URL을 가지고 있지만 난 그냥 다른 텍스트 문자열과 같은 이미지 뷰에 URL 표시 ..

누군가가 친절하게 어떻게 조정할하는 저를 보여줄 수를 검색 할 수 없습니다 그렇게하기위한 코드?

자바 초보자부터 생각해보십시오. 고맙습니다! ^^

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(); 
     } 

    } 

} 
+0

에 (TAG_IMG을)이 라인

InputStream is = (InputStream) new URL(url).getContent(); 

을 변경? 문제인가, 아니면 imageLoader인가? 너 – Zoleas

+0

? String imageURL = directory.getString (TAG_IMG); – user1781367

+0

할 때 String imageURL = directory.getString (TAG_IMG); 문자열이 null입니까? 그렇다면 json 문자열을 로깅 할 수 있습니까? – Zoleas

답변

4

JSONObject에서 URL을 가져 오기 위해 imageURL을 채워야합니다. JSONObject에 이미지 배열이 있다고 생각합니다.

먼저 시도해보십시오.

String imageURL = directory.getString(TAG_IMG); 
    //then 
    ImageView imagePhoto = (ImageView) findViewById(R.id.photo);  
    ImageLoader imgLoader = new ImageLoader(getApplicationContext());   
    imgLoader.DisplayImage(imageURL, imagePhoto); 

둘 다 쓸모없는 경우가

JSONArray imageObj = directory.getJSONArray(TAG_IMG); 
JSONObject img = imageObj.getJSONObject(0); 
String imageURL = img.getString("NewTAG"); 
    //then 
ImageView imagePhoto = (ImageView) findViewById(R.id.photo);  
ImageLoader imgLoader = new ImageLoader(getApplicationContext());   
imgLoader.DisplayImage(imageURL, imagePhoto); 

작동하지 않는 경우. ImageLoder 클래스에서 어딘가에 이미지 URL = directory.getString이어야한다이

InputStream is = (InputStream) new URL(url).openConnection().getInputStream(); 
+0

@Bans, 저에게이 문제를 도와 주셔서 감사합니다. 불행히도, 둘 다 작동하지 않았다. 그것은 이름과 이메일 주소를 포함한 빈 내용을 표시합니다 .. – user1781367

+0

디버그 모드를 시도하고 디렉토리 json 객체를보십시오. 어쩌면이 필드 비어 –

+0

이미지의 URL을 넣어, 그것은 잘 작동합니다 .. – user1781367

관련 문제