1

I am using the following code to load an image in Android Pager, but I get a blank area instead of an image, and when I load text then I get an output.

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;

    }

Above code I m using but I m not getting where I am wrong. Please help me.

Matt
  • 74,352
  • 26
  • 153
  • 180
Lazy Lion
  • 821
  • 2
  • 9
  • 18

1 Answers1

0

try this....

    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");
     }
Android
  • 106
  • 5
  • Then the day after, Gowtham, on this 2008 thread http://stackoverflow.com/questions/381508/can-a-byte-array-be-written-to-a-file-in-c/381529#381529 said to Kev he copied his answer from another website that was actually a scraper website. Copyright problems Gowtham? – Léon Pelletier May 11 '13 at 20:11