1
我想優化我的應用程序中的照片庫,並且遇到了通用圖像加載程序。但是,將其實施到我的應用程序中的所有嘗試都失敗了。 這裏有2班從我目前的應用:活動類:使用通用圖像加載程序
public class Galerija extends Activity {
ArrayList<RSSItem> lista = new ArrayList<RSSItem>();
ArrayList<String> lst_slika = new ArrayList<String>();
RSSItem tempItem = new RSSItem();
ImageAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_galerija);
try
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader myReader = sp.getXMLReader();
URL url = new URL("http://erdut.gausstesting.info/generateXML/galerija.php");
XMLHandler myXMLHandler = new XMLHandler();
myReader.setContentHandler(myXMLHandler);
myReader.parse(new InputSource(url.openStream()));
lista = myXMLHandler.getRss_lista();
lst_slika = lista.get(0).getImages();
} catch (Exception e) {
System.out.println(e);
}
adapter = new ImageAdapter(this, lst_slika);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
});
} }
這裏是適配器類:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<String> lista;
public ImageAdapter(Context c, ArrayList<String> lista) {
mContext = c;
this.lista = lista;
}
public int getCount() {
return lista.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(150, 150));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(0, 0, 0, 0);
} else {
imageView = (ImageView) convertView;
}
new ImageDownloadTask(imageView).execute(lista.get(position));
return imageView;
}}
我想通過使用通用圖像裝載機修改這些類(或任何其他方法以緩存我的圖像),因爲目前我的照片庫活動由於內存不足錯誤而崩潰。
嗯,這給了我一個錯誤。 構造函數ImageLoader(Context)未定義。 快速修復:刪除參數以匹配'ImageLoader()' –
我也有這個相同的錯誤 – wiseindy