如何在 Android Gallery 中显示本地存储中下载的图像
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以看到两个问题:
1)您的 BaseAdapter 子类为其 getCount 方法返回计数 0。这意味着 GalleryView 认为没有任何内容可显示。
2)更重要的是,您的匿名 BaseAdapter 子类没有数据源。图库旨在显示项目的滚动条,因此它希望您的适配器具有要显示的项目集合。您应该考虑执行以下操作之一:
数据项传递给构造函数。
一个 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:
of data items to the constructor.
a CursorAdapter, passing a cursor of
data items to the constructor.
choose to stick with the BaseAdapter,
you should add some sort of data
member to the class.