如何在 Android Gallery 中显示本地存储中下载的图像

发布于 2024-10-23 11:50:24 字数 3595 浏览 6 评论 0原文

public void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  

    setContentView(R.layout.transparentpanel); 

    id_pubblicazione_md5 = getIntent();
    id_pubb_md5 = id_pubblicazione_md5.getStringExtra("id_md5");
    elenco_id_pagine = id_pubblicazione_md5.getIntegerArrayListExtra("elenco_id_pagine");

    g = (Gallery) findViewById(R.id.sfogliabile);

    LoadingSfogliabile ldsf = new LoadingSfogliabile();
    ldsf.execute();
}

public class LoadingSfogliabile extends AsyncTask<Bitmap, Bitmap, Bitmap>{

    @Override
    protected void onPostExecute(final Bitmap b) {
        System.out.println("onPostExecute");
        g.setAdapter(new BaseAdapter() {

            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i = new ImageView(getBaseContext());
                i.setImageBitmap(b);
                i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
                return i;
            }

            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
            }

            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return position;
            }

            public int getCount() {
                // TODO Auto-generated method stub
                return 0;
            }
        });
    }


    @Override
    protected Bitmap doInBackground(Bitmap... params) {
        System.out.println(params.length);
        params = setSfogliabile();
        System.out.println(setSfogliabile().length);
        System.out.println(params.length);
        return params[0];
    }
}


public Bitmap[] setSfogliabile() {
    Bitmap[] pagine = new Bitmap[elenco_id_pagine.size()];

    /*************************************** FILE SYSTEM **************************************/
    dir_pag = new File(ConfigApp.absolutePathPubb+id_pubb_md5, "pagine");
    dir_pag.mkdirs();
    dir_thumb = new File(ConfigApp.absolutePathPubb+id_pubb_md5, "thumb");
    dir_thumb.mkdirs();

    for(int y = 0; y < elenco_id_pagine.size(); y++) {
        pagg = new File(dir_pag, Integer.toString(y+1));
        pagg.mkdirs();

        id_elemento = new File(pagg, (elenco_id_pagine.get(y)).toString());
        id_elemento.mkdirs();

        jpg_pagina = new File(id_elemento, ((elenco_id_pagine.get(y)).toString())+".jpg");

        try { 

    /************************** SALVATAGGIO DELLE IMMAGINI IN LOCALE **************************/
            String pagina = ConfigApp.urlPubbDir+id_pubb_md5+"/pagine/"+Integer.toString(y+1)+"/"+((elenco_id_pagine.get(y)).toString())+"/"+((elenco_id_pagine.get(y)).toString())+".jpg";
            FileOutputStream fos = new FileOutputStream(jpg_pagina.getAbsolutePath());
            pagine[y] = imd.downloadBitmap(pagina);
            pagine[y].compress(CompressFormat.JPEG, 90, fos);

    /******************************************************************************************/

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


    }
    /************************************* FINE FILE SYSTEM ***********************************/
    return pagine;
}`

怎么了?!?!?!

我不明白这是什么问题!!

public void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  

    setContentView(R.layout.transparentpanel); 

    id_pubblicazione_md5 = getIntent();
    id_pubb_md5 = id_pubblicazione_md5.getStringExtra("id_md5");
    elenco_id_pagine = id_pubblicazione_md5.getIntegerArrayListExtra("elenco_id_pagine");

    g = (Gallery) findViewById(R.id.sfogliabile);

    LoadingSfogliabile ldsf = new LoadingSfogliabile();
    ldsf.execute();
}

public class LoadingSfogliabile extends AsyncTask<Bitmap, Bitmap, Bitmap>{

    @Override
    protected void onPostExecute(final Bitmap b) {
        System.out.println("onPostExecute");
        g.setAdapter(new BaseAdapter() {

            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i = new ImageView(getBaseContext());
                i.setImageBitmap(b);
                i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
                return i;
            }

            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
            }

            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return position;
            }

            public int getCount() {
                // TODO Auto-generated method stub
                return 0;
            }
        });
    }


    @Override
    protected Bitmap doInBackground(Bitmap... params) {
        System.out.println(params.length);
        params = setSfogliabile();
        System.out.println(setSfogliabile().length);
        System.out.println(params.length);
        return params[0];
    }
}


public Bitmap[] setSfogliabile() {
    Bitmap[] pagine = new Bitmap[elenco_id_pagine.size()];

    /*************************************** FILE SYSTEM **************************************/
    dir_pag = new File(ConfigApp.absolutePathPubb+id_pubb_md5, "pagine");
    dir_pag.mkdirs();
    dir_thumb = new File(ConfigApp.absolutePathPubb+id_pubb_md5, "thumb");
    dir_thumb.mkdirs();

    for(int y = 0; y < elenco_id_pagine.size(); y++) {
        pagg = new File(dir_pag, Integer.toString(y+1));
        pagg.mkdirs();

        id_elemento = new File(pagg, (elenco_id_pagine.get(y)).toString());
        id_elemento.mkdirs();

        jpg_pagina = new File(id_elemento, ((elenco_id_pagine.get(y)).toString())+".jpg");

        try { 

    /************************** SALVATAGGIO DELLE IMMAGINI IN LOCALE **************************/
            String pagina = ConfigApp.urlPubbDir+id_pubb_md5+"/pagine/"+Integer.toString(y+1)+"/"+((elenco_id_pagine.get(y)).toString())+"/"+((elenco_id_pagine.get(y)).toString())+".jpg";
            FileOutputStream fos = new FileOutputStream(jpg_pagina.getAbsolutePath());
            pagine[y] = imd.downloadBitmap(pagina);
            pagine[y].compress(CompressFormat.JPEG, 90, fos);

    /******************************************************************************************/

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


    }
    /************************************* FINE FILE SYSTEM ***********************************/
    return pagine;
}`

What's the matter?!?!?!

I don't understand what is the problem!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宛菡 2024-10-30 11:50:24

我可以看到两个问题:

1)您的 BaseAdapter 子类为其 getCount 方法返回计数 0。这意味着 GalleryView 认为没有任何内容可显示。

2)更重要的是,您的匿名 BaseAdapter 子类没有数据源。图库旨在显示项目的滚动条,因此它希望您的适配器具有要显示的项目集合。您应该考虑执行以下操作之一:

  • 使用 ArrayAdapter,传递数组
    数据项传递给构造函数。
  • 使用
    一个 CursorAdapter,传递一个游标
    数据项传递给构造函数。
  • 如果你
    选择坚持使用 BaseAdapter,
    你应该添加某种数据
    班级成员。

I can see two issues:

1) Your BaseAdapter subclass returns a count of 0 for its getCount method. That means the GalleryView thinks there is nothing to display.

2) On a larger note, your anonymous BaseAdapter subclass doesn't have a data source. The Gallery is intended to display a scrolling strip of items, so it expects your adapter to have a collection of items to display. You should consider doing one of the following:

  • use an ArrayAdapter, passing an array
    of data items to the constructor.
  • use
    a CursorAdapter, passing a cursor of
    data items to the constructor.
  • If you
    choose to stick with the BaseAdapter,
    you should add some sort of data
    member to the class.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文