【发布时间】:2014-02-26 17:26:40
【问题描述】:
我在尝试理解如何为Asynctask 中的数据对象设置值时遇到了麻烦。从几个读数中我发现我无法在Asynctask 的doInBackground() 部分设置值。话虽如此,我很困惑在哪里设置它们。我通过检查知道这些值存在,但是当我尝试通过执行milTuxs.urlTuxName/urlTuxPhoto 在onPostExecute 中设置urlTuxName/urlTuxPhoto 值时,无法识别这些变量。任何帮助将不胜感激。
private class LoadImageTask extends AsyncTask<ArrayList<Tuxedo>, Void, ArrayList<TuxLoader>> {
private String name;
Bitmap imageBitmap;
ArrayList<TuxLoader> milTuxs = new ArrayList<TuxLoader>();
@Override
protected ArrayList<TuxLoader> doInBackground(ArrayList<Tuxedo>... tuxList) {
ArrayList<Tuxedo> t = tuxList[0];
System.out.println("tuxUrlList count =" + t.size());
// TODO Auto-generated method stub
try {
for(int i=0; i< t.size(); i++) {
Tuxedo tempList = t.get(i);
URL imageUrl = new URL(tempList.tuxUrlPath);
imageBitmap = DecodeBitmapSampleSize(imageUrl, 70, 70);
addBitmapToMemoryCache(String.valueOf(imageUrl), imageBitmap);
name = tempList.tuxName;
//System.out.println("Tux name is " + name);
TuxLoader tuxLoad = new TuxLoader();
tuxLoad.urlName = name;
tuxLoad.bitmap = imageBitmap;
//tuxLoad.urlTuxName = (TextView) findViewById(R.id.grid_label);
//tuxLoad.urlTuxName.setText(name);
//tuxLoad.urlPhoto = (ImageView) findViewById(R.id.grid_image);
//tuxLoad.urlPhoto.setImageBitmap(imageBitmap);
milTuxs.add(tuxLoad);
//System.out.println("Mills Tuxs = " + milTuxs);
}
} catch (Exception e) {
Log.e("error", "Image Download Failed");
//t.bitmap = null;
imageBitmap = null;
}
return milTuxs;
}
@Override
protected void onPostExecute(ArrayList<TuxLoader> milTuxs) {
super.onPostExecute(milTuxs);
// TODO Auto-generated method stub
System.out.println("PexMills Tuxs = " + milTuxs);
//Set tuxGrid as the GridView variable
GridView tuxGrid = (GridView) findViewById(R.id.tux_grid_view);
CustomAdapterGrid4 adapter = (new CustomAdapterGrid4(TuxedoActivity2.this, milTuxs));
tuxGrid.setAdapter(adapter);
}
【问题讨论】:
标签: android android-asynctask android-imageview android-gridview