我在手机内保存了一些图像并将图像路径插入数据库。我想使用数据库中的图像路径并将其显示在 gridview 中。现在我可以创建一个网格视图来在画廊应用程序中显示图像。但我真的不知道如何根据数据库路径显示图像。如果可能的话,有人可以在这个问题上启发我吗?任何评论将不胜感激。
下面的代码用于在图库中显示图像。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.phone_tab);
final String[] columns = { MediaColumns.DATA, BaseColumns._ID };
final String orderBy = BaseColumns._ID;
Cursor imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
int image_column_index = imagecursor.getColumnIndex(BaseColumns._ID);
this.count = imagecursor.getCount();
this.thumbnails = new Bitmap[this.count];
this.arrPath = new String[this.count];
this.thumbnailsselection = new boolean[this.count];
for (int i = 0; i < this.count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
int dataColumnIndex = imagecursor.getColumnIndex(MediaColumns.DATA);
thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
getApplicationContext().getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null);
arrPath[i]= imagecursor.getString(dataColumnIndex);
}
GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
imageAdapter = new ImageAdapter();
imagegrid.setAdapter(imageAdapter);
imagecursor.close();
final Button selectBtn = (Button) findViewById(R.id.select_btn);
selectBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final int len = thumbnailsselection.length;
int cnt = 0;
String selectImages = "";
for (int i =0; i<len; i++)
{
if (thumbnailsselection[i]){
cnt++;
selectImages = selectImages + arrPath[i] + "|";
}
}
if (cnt == 0){
Toast.makeText(getApplicationContext(),
"Please select at least one image",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"You've selected Total " + cnt + " image(s).",
Toast.LENGTH_LONG).show();
Log.d("SelectedImages", selectImages);
Intent input = new Intent(v.getContext(), InputScreen.class);
input.putExtra("selectImages", selectImages+"");
StringBuffer urlString = new StringBuffer();
replaceContentView("InputScreen", input);
}
}
});
}
值 [2] 返回为 /mnt/sdcard/ImageFolder/Image1.jpg。
String values[] = helper.get_user_image(useremail);
String filepath = values[2];