I am extracting images from a url. Instead of caching images, is it possible to accidentally save it in a SQLite database?
public ImageAdapter(Context c) { this.myContext = c; } public int getCount() { return this.myRemoteImages.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(this.myContext); try { URL aURL = new URL(myRemoteImages[position]); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); Bitmap bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); Log.v(imageUrl, "Retrieving image"); i.setImageBitmap(bm); } catch (IOException e) { Log.e("DEBUGTAG", "Remtoe Image Exception", e); } i.setScaleType(ImageView.ScaleType.FIT_CENTER); if(Build.VERSION.SDK_INT >= 11){ i.setLayoutParams(new Gallery.LayoutParams(450, 300)); return i; } else{ i.setLayoutParams(new Gallery.LayoutParams(125, 125)); return i; } } public float getScale(boolean focused, int offset) { return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset))); } }
EDIT: set imageAdapter to load images in gallery
((Gallery) findViewById(R.id.gallery)) .setAdapter(new ImageAdapter(MainMenu.this));
source share