2017-09-01 64 views
-1

我怎樣才能讓這個URL的圖像..使用Volley? 我已經解析了所有其他的數據..只有url圖像...有些幫助? 這是我的代碼如何解析JSON數據與排球

String id =imageName.getText().toString().trim(); 
    if (id.equals("")) { 
     Toast.makeText(this, "Please enter an id", Toast.LENGTH_LONG).show(); 
     return; 
    } 
    loading = ProgressDialog.show(this, "Please wait...", "Fetching...", false, false); 

    String url = Url + imageName.getText().toString().trim(); 
    Log.d("DIRECT", url); 
    StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() { 
     @Override 
     public void onResponse(String response) { 
      loading.dismiss(); 
      showJSON(response); 
     } 
    }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 

// Toast.makeText(MainActivity.this,error.getMessage()的toString(),Toast.LENGTH_LONG。).show(); } });

RequestQueue requestQueue = Volley.newRequestQueue(this); 
    requestQueue.add(stringRequest); 
} 

private void showJSON(String response) { 
    Bitmap bmp = null; 
    String code = ""; 
    String vende = ""; 
    String image=""; 
    String fecha = ""; 
    String det = ""; 

    try { 
     JSONObject jsonObject = new JSONObject(response); 
     JSONArray result = jsonObject.getJSONArray("result"); 
     JSONObject collegeData = result.getJSONObject(0); 

     code = collegeData.getString("codigo"); 
     vende = collegeData.getString("articulos"); 
     fecha = collegeData.getString("detalle"); 
     det = collegeData.getString("precio"); 
    //how parsing the url image 

    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
    // texto.setText("Code:\t" + code + "\nVendedeor:\t" + vende + "\nfecha:\t" + fecha + "\ndetalle:\t" + det); 
    imageName.setText(code); 
    art.setText(vende); 
    // imageView.setImageBitmap(bmp); 
    deta.setText(fecha); 
    pre.setText(det); 

Log.d( 「RES」,將String.valueOf(預)+將String.valueOf(技術)+將String.valueOf(imageName));

提前致謝!

+0

使用圖書館像畢加索和負荷的形象像這樣Picasso.with(上下文).load( 「圖片網址」) .into(ImageView的); 使用畢加索,添加這個作爲依賴編譯「com.squareup.picasso:picasso:2.4.0」 –

+0

謝謝你...要嘗試 – Widy

回答

0

Android畢加索圖書館是一個偉大的圖書館下載和緩存圖像。

https://github.com/square/picasso

只要你能在ImageView的加載圖像網址爲:

Picasso.with(this).load("your_image_url").into(imageView); 
+0

謝謝你們所有的人現在工作好:) – Widy

+0

請投票並標記爲答案如果這對你有用。 –