2013-05-08 3 views
0
나는 연속적 텍스트 뷰를 표시했지만 이미지를 표시하는 방법을 내 코드

어떻게 JSON에서 목록보기에 이미지를 표시하는 동적

public class AndroidJSONParsingActivity extends ListActivity { 


    // url to make request 
    private static String url = "***MY URL***"; 

    // JSON Node names 

    private static final String TAG_ID = "id"; 
    private static final String TAG_NAME = "name"; 
    private static final String TAG_PRICE = "price"; 
    private static final String TAG_URL = "hosting_thumbnail_url"; 


    // contacts JSONArray 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_android_jsonparsing); 

     // Hashmap for ListView 
     ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>(); 

     // Creating JSON Parser instance 
     JSONParser jParser = new JSONParser(); 

     // getting JSON string from URL 
     JSONArray json = jParser.getJSONFromUrl(url); 

     try { 
      // Getting Array of Contacts 


      // looping through All Contacts 
      for(int i = 0; i < json.length(); i++){ 
       JSONObject c = json.getJSONObject(i); 

       // Storing each json item in variable 
       String id = c.getString(TAG_ID); 
       String name = c.getString(TAG_NAME); 
       String email = c.getString(TAG_PRICE); 
       //String image1 = c.getString(TAG_URL); 

       // creating new HashMap 
       HashMap<String, String> map = new HashMap<String, String>(); 

       // adding each child node to HashMap key => value 
       map.put(TAG_ID, id); 
       map.put(TAG_NAME, name); 
       map.put(TAG_PRICE, email); 
       //map.put(TAG_URL, image1); 


       // adding HashList to ArrayList 
       contactList.add(map); 
      } 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

     /** 
     * Updating parsed JSON data into ListView 
     * */ 
     ListAdapter adapter = new SimpleAdapter(this, contactList, 
       R.layout.list_item, 
       new String[] { TAG_NAME, TAG_PRICE }, new int[] { 
         R.id.name, R.id.email }); 

     setListAdapter(adapter); 


    } 

} 
입니다

특정 URL에 배치됩니다 JSON에서 텍스트 및 이미지를 나열 할

내가이 같은 목록보기 싶어 "http://pic002.cnblogs.com/images/2012/372551/2012021011374176.jpg"

답변

2

사용자 지정 목록 어댑터를 작성해야합니다. "android custom listadapter image"에 대한 Google. 첫 번째 히트는 this입니다. 괜찮은 예입니다.

0

SimonSays가 말한 것처럼 사용자는 ListView 어댑터 클래스와 그 getView() 메서드를 구현해야합니다. 동적 ListView에 이러한 JSON 객체를 취득 할 계획이라면 난 강력하게, 즉 그것을 얻을 것 즉시 ListView 해당 JSON 객체에서 데이터를 설정합니다 일부 Thread 메커니즘을 사용하는 것이 좋습니다

- 즉 AsyncTask

관련 문제