2013-04-24 5 views
1

Я воспользовался следующим кодом для загрузки изображения в Android пейджере, но я получаю пустую область вместо изображения, а когда загружаю текст, то получаю вывод.не может загрузить изображение в android Adapter

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

При загрузке из файла, проверьте, существует ли файл локально, попробуйте uotput на thumb_url в консоли. – Demonick

+0

Пожалуйста, добавьте макет xml и код ListProduct – tbkn23

+0

ListProduct.KEY_THUMB_URL это адрес? (например, http://www.site.com/img.jpg)? или ressource в вашем Android-приложении? – VincentLamoute

ответ

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"); 
    } 
+0

Скопировано из http://androiddev.orkitra.com/?p=43429 –

+0

@Nikhil - можете ли вы побывать в чате: http://chat.stackoverflow.com/rooms/28819 – Kev

+0

Затем на следующий день, Gowtham, об этом 2008 thread http://stackoverflow.com/questions/381508/can-a-byte-array-be-written-to-a-file-in-c/381529#381529 сказал Кеву, что он скопировал свой ответ с другого веб-сайта, который был фактически скребковым сайтом. Проблемы с авторскими правами Gowtham? –

Смежные вопросы