[英]String Url image to bitmap
我是Android新手,我有一個活動類,該活動類從url獲取Json字符串並將Json數組轉換為對象。我正在解析對象,但是圖像以textview的形式返回,這不是我想要的。 試圖找到我在[這里]尋求的解決方案,但這只是給我可繪制的圖標,而不是我需要的圖像。任何幫助或建議都將不勝感激
下面是我的代碼。
ListAdapter adapter = new SimpleAdapter(this, List,
R.layout.list,
new String[] {TAG_PHOTOS }, new int[] {
R.id.image});
setListAdapter(adapter);
// selecting single ListView item
final ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ImageView photoThumbnailUrl = ((ImageView)
view.findViewById(R.id.image));
Bitmap bMap = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
Bitmap bMapScaled = Bitmap.createScaledBitmap(bMap, 150, 100, true);
photoThumbnailUrl.setImageBitmap(bMapScaled);
photoThumbnailUrl.setImageResource(R.drawable.ic_launcher);
photoThumbnailUrl.getDrawable();
System.out.println(photoThumbnailUrl);
lv.addView(photoThumbnailUrl);
}
});
要在android中使用imageview,您需要自定義適配器。 並且我建議您使用LazyAdapter,因為一段時間后會需要它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.