我使用以下代码在Android Pager中加载图像,但是我得到一个空白区域而不是图像,当我加载文本时,我得到一个输出。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View vi=container;
//if(container==null)
vi = inflater.inflate(R.layout.fragment_pager_list, null);
TextView title = (TextView)vi.findViewById(R.id.textTitle); // title
ImageView thumb_image=(ImageView)vi.findViewById(R.id.imageProduct);
// thumb image
HashMap<String, String> song = new HashMap<String, String>();
song = ListProduct.productList.get(mNum);
// Setting all values in listview
title.setText(song.get(ListProduct.KEY_TITLE));
Bitmap bitmap = BitmapFactory.decodeFile
(song.get(ListProduct.KEY_THUMB_URL));
thumb_image.setImageBitmap(bitmap);
return vi;
}
以上代码我正在使用,但我没有得到我错的地方。请帮帮我。
答案 0 :(得分:0)
试试这个......
try {
URL url = new URL(ListProduct.KEY_THUMB_URL);
HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(url.toURI());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
InputStream input = b_entity.getContent();
bitmap = BitmapFactory.decodeStream(input);
//// Set Bitmap to Imageview
thumb_image.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
Log.d("log", "bad url");
} catch (IOException e) {
Log.d("log", "io error");
}