hi I’ve could use a little help understanding the imageadapter extending the baseadapter. I’m on the homestretch of the app I’ve been working on for the last month and am stumped. A little about my project. It keeps track of vehicles. For any vehicle the user can take as many photos with the camera as they would like. This part works. I can take a photo and it saves it in the internal storage. I then save that path to a sqlite table. My database has an image id (_id) ex. 1, a vehicle id (v_id) ex 1, and a path to the image (i_image) ex /data/data/com.okc.vinstick/files/img_20120111_090000.jpg. I verified the image file and the database entry are being saved correctly. Now to the tough part: Displaying the images in a GridView. The ImageAdapter example i’m trying to follow is like this:
public class ImageAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public ArrayList<ImageItem> images = new ArrayList<ImageItem>();
public ImageAdapter() {
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void initialize() {
images.clear();
final String[] columns = { MediaStore.Images.Thumbnails._ID };
final String orderBy = MediaStore.Images.Media._ID;
Cursor imagecursor = null;
try {
ContextWrapper context = MorePhotoTesting.this;
imagecursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
} catch(Exception e) {
e.printStackTrace();
}
if(imagecursor != null){
int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
int count = imagecursor.getCount();
for (int i = 0; i < count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
ImageItem imageItem = new ImageItem();
imageItem.id = id;
lastId = id;
imageItem.img = MediaStore.Images.Thumbnails.getThumbnail(getApplicationContext().getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null);
images.add(imageItem);
}
imagecursor.close();
}
notifyDataSetChanged();
}
I believe once I understand the initialize() I can hammer out the getView(). Obviously the example is using the Mediastore where I will be using app internal storage. I’m just lost, and my research has come up empty. I just don’t see how to replace the Mediastore stuff with my database code. If anyone can point me in the right direction that would be great! By the way the example uses a class:
class ImageItem {
boolean selection;
int id;
Bitmap img;
}
the calls from the main activity look something like this:
imageAdapter = new ImageAdapter();
imageAdapter.initialize();
imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
imagegrid.setAdapter(imageAdapter);
I apologize but this is my first project dealing with these features.
I’m not totally sure if there’s a specific question here, but I notice in your code the following line:
Since you are storing your images in the internal phone storage, you should probably be using
MediaStore.Images.Media.INTERNAL_CONTENT_URI, at least.I also notice you’re using
getThumbnail(). This will only work with content stored on the sdcard.