이 내가 모두 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);
}
});
}
}
}
귀하의 질문은 매우 명확하지 왜. 이미 잭슨을 분석 했니? 해시 맵에 비트 맵을 저장하고 싶습니까, 아니면 이미지 뷰에서 이미지를 비동기로 다운로드 하시겠습니까? (나는 마지막 것을 권합니다) –
하나씩 이미지를 다운로드하여 비트 맵에 저장하십시오. Arraylist m = new ArrayList ; –
deepak825
또는 범용 이미지 로더 개념을 사용하십시오. – deepak825