2014-11-27 4 views
-2

이 내가 모두 Android에 이미지 및 제목을 표시 할 것입니다 원하는 내 Json 인코딩 된 코드입니다하지만 난 이미지HashMap에서 URL을 이미지로 변환하는 방법은 무엇입니까?

{"lists": 
    [{"post_title":"kigs", 
    "post_img":"post_img":"http://truzzinfotech.com/wp-content/uploads/2014/04/19-150x150.jpg"}, 

    {"post_title":"Lacolline", 
    "post_img":"http://truzzinfotech.com/wp-content/uploads/2014/04/19-150x150.jpg"}, 

    {"post_title":"Cricket", 
    "post_img":"http://truzzinfotech.com/wp-content/uploads/2014/047-150x150.jpg"},  
    ], 
    "success":1} 

를 표시 할 수없는 오전이 점점 이미지에 대한 내 안드로이드 코드 제목

공용 클래스 포트폴리오는 {

// Progress Dialog 


private ProgressDialog pDialog; 


ImageView image; 




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

     ArrayList<HashMap<String, String>> portfoliosList; 

     // url to get all products list 
     private static String url_all_portfolios = "http://truzzinfotech.com/wp-content/themes/truzz/getPortfolio.php"; 

     // JSON Node names 
     private static final String TAG_SUCCESS = "success"; 
     private static final String TAG_PORTFOLIOS = "lists"; 
     static final String TAG_TITLE = "post_title"; 
     static final String TAG_IMAGE = "post_img"; 

     // products JSONArray 
     JSONArray lists = null; 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.portfolio); 

       //ListView lv = getListView(); 

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

      // Loading products in Background Thread 
      new LoadAllPortfolios().execute(); 


      image = (ImageView)findViewById(R.id.portImg); 
     } 


     /** 
     * Background Sync Task to Load all product by making HTTP Request 
     * */ 
     class LoadAllPortfolios extends AsyncTask<String, String, String> { 

      /** 
      * Before starting background thread Show Progress Dialog 
      * */ 
      @Override 
      protected void onPreExecute() { 
       super.onPreExecute(); 
       pDialog = new ProgressDialog(Portfolio.this); 
       pDialog.setMessage("Loading portfolio. Please wait..."); 
       pDialog.setIndeterminate(false); 
       pDialog.setCancelable(false); 
       pDialog.show(); 
       //Toast.makeText(getBaseContext(), "Enter in loading" ,Toast.LENGTH_LONG).show(); 
      } 

      /** 
      * getting All products from url 
      * */ 
      protected String doInBackground(String... args) { 
       // Building Parameters 
       //Toast.makeText(getBaseContext(), "Enter in doInBackground" ,Toast.LENGTH_LONG).show(); 
       List<NameValuePair> params = new ArrayList<NameValuePair>(); 
       // getting JSON string from URL 

       JSONObject json = jParser.makeHttpRequest(url_all_portfolios,"GET", params); 


       Log.d("All Products: ", json.toString()); 

       try { 

        //lists = new JSONArray(TAG_PORTFOLIOS); 
         int success = json.getInt(TAG_SUCCESS); 

       if (success == 1) { 

         // portfolios found 
         // Getting Array of portfolios 

         lists = json.getJSONArray(TAG_PORTFOLIOS); 
         // c = null; 

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


          String title = c.getString(TAG_TITLE); 
          String image = c.getString(TAG_IMAGE); 

          Log.d("Item name: ",title); 
          HashMap<String, String> map = new HashMap<String, String>(); 

          URL url = new URL(image); 
          HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
          con.setDoInput(true); 
          con.connect(); 
          InputStream input = con.getInputStream(); 
          Bitmap bitmap = BitmapFactory.decodeStream(input); 

          //InputStream in = new URL(TAG_IMAGE).openStream(); 
          //bmp = BitmapFactory.decodeStream(in); 
          map.put(TAG_TITLE, title); 
          map.put(TAG_IMAGE, image); 
          //map.put("image", jsonobject.getString("image")); 


          portfoliosList.add(map); 
         } 
        } else { 
         // no products found 
         // Launch Add New product Activity 
         Toast.makeText(getBaseContext(), "No Portfolio Found" ,Toast.LENGTH_LONG).show(); 
        } 

       } catch (JSONException e) { 
        // TODO Auto-generated catch block 
        Toast.makeText(getBaseContext(), "No Data Found" ,Toast.LENGTH_LONG).show(); 
        e.printStackTrace(); 
       } catch (MalformedURLException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

       return null; 
      } 

      /** 
      * After completing background task Dismiss the progress dialog 
      * **/ 
      protected void onPostExecute(String file_url) { 
       // dismiss the dialog after getting all products 
       pDialog.dismiss(); 
       // updating UI from Background Thread 
       runOnUiThread(new Runnable() { 
        public void run() { 
         /** 
         * Updating parsed JSON data into ListView 
         * */ 
         ListAdapter adapter = new SimpleAdapter(
           Portfolio.this, portfoliosList, 
           R.layout.list_item, new String[] { TAG_TITLE,TAG_IMAGE }, 
           new int[] {R.id.name, R.id.portImg}); 
         // updating listview 
         setListAdapter(adapter); 
        } 
       }); 

      } 

     } 
} 
+1

귀하의 질문은 매우 명확하지 왜. 이미 잭슨을 분석 했니? 해시 맵에 비트 맵을 저장하고 싶습니까, 아니면 이미지 뷰에서 이미지를 비동기로 다운로드 하시겠습니까? (나는 마지막 것을 권합니다) –

+0

하나씩 이미지를 다운로드하여 비트 맵에 저장하십시오. Arraylist m = new ArrayList ; – deepak825

+0

또는 범용 이미지 로더 개념을 사용하십시오. – deepak825

답변

0

이 같이 시도 ListActivity를 확장 , 이미지 뷰 visit here

+0

이미지를 문자열로 표시하지만 이미지 뷰에 표시하는 방법 – jayant

+0

https : //code.google.com/p/android-query/wiki/ImageLoading –

1

에서보기 이미지

JSONArray data = yourjson.getJSONArray("lists"); 

ArrayList<String> imgurls = new ArrayList<String>(); 

for(int i = 0; i < data.length(); i++){ 
    imgUrls.add(data.getJSONObject(i).getString("post_img")) 
} 

당신의 하나가 처리해야하는 더러운 물건의 대부분 이미지보기 경우

com.android.volley.toolbox.NetworkImageView 
     android:id="@+id/networkImageView" 
     android:layout_width="150dp" 
     android:layout_height="170dp" 
     android:layout_centerHorizontal="true" /> 

NetworkImageView 네트워킹 중에이하는 구글에 의해 발리 라이브러리를 사용할 수 있습니다 정말 잘 관리하는 목록보기의 일부입니다.

ImageLoader mImageLoader; 
NetworkImageView mNetworkImageView; 
private static final String IMAGE_URL = 
    "http://developer.android.com/images/training/system-ui.png"; 
... 

// Get the NetworkImageView that will display the image. 
mNetworkImageView = (NetworkImageView) findViewById(R.id.networkImageView); 

// Get the ImageLoader through your singleton class. 
// mImagaLoader is actually the request Queue of the manages all the caching 
// and requesting image from the network in not present in cache 
mImageLoader = MySingleton.getInstance(this).getImageLoader(); 

// Set the URL of the image that should be loaded into this view, and 
// specify the ImageLoader that will be used to make the request. 
mNetworkImageView.setImageUrl(IMAGE_URL, mImageLoader); 

참조 : https://developer.android.com/training/volley/request.html

mImageLoader 참조 : https://developer.android.com/training/volley/requestqueue.html#singleton 설정하는 방법 싱글 톤 클래스와

관련 문제