1

我正在使用以下代码在 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;

    }

我正在使用上面的代码,但我没有得到我错的地方。请帮我。

4

1 回答 1

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");
     }
于 2013-04-24T11:33:26.033 回答