无法在网格视图中显示来自网址的图片

时间:2012-11-29 02:40:38

标签: android image jsoup

嗨我正在尝试在网格视图中显示从url(使用jsoup)获取的图像。它设法检索我要加载的图像数量,但不显示实际图像本身。实际图像不是音符

这是截图:

enter image description here

这是我获取网址并显示它的代码,我使用了“lazy gallery”:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery);


        this.setRequestedOrientation(
                ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        Button refresh = (Button)findViewById(R.id.btn_refresh);
        refresh.setOnClickListener(this);

        ImageButton home = (ImageButton)findViewById(R.id.btn_home);
        home.setOnClickListener(this);

        // Loading products in Background Thread
        new LoadThumbnails().execute();

        //Getting adapter and parse in results      
        list=(GridView)findViewById(R.id.list);
        adapter=new LazyAdapter(this, htmlList);        
        list.setAdapter(adapter);

        // Click event for single list row
        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {        

                Intent intent = new Intent();
                intent.setClassName("com.scba", "com.scba.gallery.EnlargedImage");
                intent.putExtra("item", actualImage);
                startActivityForResult(intent, GET_INTENT_CODE);

                }
        }); 
    }

       /**
     * Background Async Task to Load all product by making HTTP Request
     * */
    class LoadThumbnails extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
         @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(PhotoGallery.this);
            pDialog.setMessage("Loading" + "\n" + "Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        } 

        /**
         * getting All products from url
         * */
        protected String doInBackground(String... args) {
            try {


                Document doc = Jsoup.connect("http://www.s-cba.org.sg/events/2011/photo111001_en.shtml").get();
                //Elements trs = doc.select("td.text tr td");
                //remove header row


                /* for (int i = 0; i < 43; i++)
                    {
                    Element link = doc.select("td.text tr td a").get(i);
                    String relHref = link.attr("href");
                    //System.out.println("Blog: " + relHref);
                    } */

                    for (int c = 0; c < 43; c++)
                    {
                    Element link = doc.select("td.text tr td a img").get(c);
                    String url = link.absUrl("src");
                    System.out.println("Blog: " + url);


                    HashMap<String, String> map = new HashMap<String, String>();

                     // adding each child node to HashMap key => value
                    map.put("photo",url); 

                    // adding HashList to ArrayList
                    htmlList.add(map); 

                    //System.out.println(htmlList);
                    }

            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }


    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        adapter.notifyDataSetChanged();
    }
    }


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v.getId() == R.id.btn_refresh)
        {
            photosList.clear();
            // Loading products in Background Thread
            new LoadThumbnails().execute();
        }
        else if(v.getId() == R.id.btn_home)
        {

            Intent intent = new Intent();
            intent.setClassName("com.scba", "com.scba.Menu");
            finish();

        }

    }
}

这是logcat输出:

11-29 02:39:13.991: D/dalvikvm(167): GC_CONCURRENT freed 384K, 6% free 9533K/10119K, paused 20ms+5ms
11-29 02:39:16.392: I/ActivityManager(91): START {cmp=com.scba/.admin.Settings} from pid 777
11-29 02:39:16.400: W/WindowManager(91): Failure taking screenshot for (180x300) to layer 21010
11-29 02:39:16.500: V/PhoneStatusBar(143): setLightsOn(true)
11-29 02:39:16.631: I/ActivityManager(91): Displayed com.scba/.admin.Settings: +214ms
11-29 02:39:21.730: W/WindowManager(91): Failure taking screenshot for (180x300) to layer 21015
11-29 02:39:21.780: V/PhoneStatusBar(143): setLightsOn(true)
11-29 02:39:24.169: I/ActivityManager(91): START {cmp=com.scba/.gallery.PhotoGallery} from pid 777
11-29 02:39:24.189: W/WindowManager(91): Failure taking screenshot for (180x300) to layer 21010
11-29 02:39:24.319: V/PhoneStatusBar(143): setLightsOn(true)
11-29 02:39:24.719: I/Process(91): Sending signal. PID: 777 SIG: 3
11-29 02:39:24.719: I/dalvikvm(777): threadid=3: reacting to signal 3
11-29 02:39:24.949: I/dalvikvm(777): Wrote stack traces to '/data/anr/traces.txt'
11-29 02:39:25.119: D/dalvikvm(777): GC_FOR_ALLOC freed 1225K, 15% free 11137K/13063K, paused 98ms
11-29 02:39:25.209: I/ActivityManager(91): Displayed com.scba/.gallery.PhotoGallery: +1s9ms
11-29 02:39:26.569: D/dalvikvm(777): GC_CONCURRENT freed 781K, 17% free 10941K/13063K, paused 20ms+22ms
11-29 02:39:27.449: D/dalvikvm(777): GC_CONCURRENT freed 408K, 15% free 11106K/13063K, paused 21ms+9ms
11-29 02:39:27.769: I/dalvikvm(777): Total arena pages for JIT: 12
11-29 02:39:28.519: D/dalvikvm(777): GC_CONCURRENT freed 474K, 15% free 11226K/13063K, paused 21ms+53ms
11-29 02:39:28.639: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7278_s.jpg
11-29 02:39:28.659: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7300_s.jpg
11-29 02:39:28.709: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7302_s.jpg
11-29 02:39:28.729: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7326_s.jpg
11-29 02:39:28.739: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7335_s.jpg
11-29 02:39:28.759: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7363_s.jpg
11-29 02:39:28.809: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7400_s.jpg
11-29 02:39:28.829: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7411_s.jpg
11-29 02:39:28.839: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7418_s.jpg
11-29 02:39:28.859: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7424_s.jpg
11-29 02:39:28.869: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7610_s.jpg
11-29 02:39:28.919: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7647_s.jpg
11-29 02:39:28.941: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7657_s.jpg
11-29 02:39:28.959: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7672_s.jpg
11-29 02:39:28.969: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7734_s.jpg
11-29 02:39:29.039: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7767_s.jpg
11-29 02:39:29.059: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_7816_s.jpg
11-29 02:39:29.069: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8219_s.jpg
11-29 02:39:29.150: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8235_s.jpg
11-29 02:39:29.159: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8243_s.jpg
11-29 02:39:29.209: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8259_s.jpg
11-29 02:39:29.229: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8327_s.jpg
11-29 02:39:29.239: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8356_s.jpg
11-29 02:39:29.259: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8375_s.jpg
11-29 02:39:29.269: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8399_s.jpg
11-29 02:39:29.320: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8401_s.jpg
11-29 02:39:29.349: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8417_s.jpg
11-29 02:39:29.359: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8419_s.jpg
11-29 02:39:29.379: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8448_s.jpg
11-29 02:39:29.429: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8469_s.jpg
11-29 02:39:29.469: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8470_s.jpg
11-29 02:39:29.480: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8527_s.jpg
11-29 02:39:29.529: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8562_s.jpg
11-29 02:39:29.549: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8594_s.jpg
11-29 02:39:29.589: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8664_s.jpg
11-29 02:39:29.639: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8688_s.jpg
11-29 02:39:29.659: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8722_s.jpg
11-29 02:39:29.680: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8752_s.jpg
11-29 02:39:29.689: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8763_s.jpg
11-29 02:39:29.730: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8869_s.jpg
11-29 02:39:29.759: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8896_s.jpg
11-29 02:39:29.789: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/DSC_8939_s.jpg
11-29 02:39:29.799: I/System.out(777): Blog: http://www.s-cba.org.sg/events/2011/111001/IMG_5276_s.jpg

1 个答案:

答案 0 :(得分:1)

请将以下代码行写入适配器的getView()方法。

imageLoader.DisplayImage(song.get("photo"), thumb_image);

而不是

imageLoader.DisplayImage(song.get(MainActivity.TAG_THUMBNAIL), thumb_image);

它将解决您的问题。