您好我已经在数据库中保存了图像的路径。如何在屏幕上显示图像?图像路径保存在“contactTest1”表中的“photo”列中! 现在我可以在屏幕上只显示每个联系人的图像路径,如下所示:
我在dbconsole.java中使用它:
private static String[] FROM = { DbConstants.NAME, DbConstants.PHOTO, DbConstants.EMAIL,DbConstants.URL_STRING,DbConstants.ADRESS,DbConstants.PHONE,_ID};
private static int[] TO ={R.id.name,R.id.edittext1};
private void showContacts(Cursor cursor) {
//set up data binding
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO);
setListAdapter(adapter);
这是我用来获取图像路径的代码:
Button sButton = (Button) findViewById(R.id.button1);
sButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I'm using to hold the content:// URI of the image
Uri currImageURI = data.getData();
getRealPathFromURI(currImageURI);
}
}
}
public String getRealPathFromURI(Uri currImageURI) {
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( currImageURI,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
poza=(EditText)findViewById(R.id.editText1);
poza.setText(currImageURI.toString());
return cursor.getString(column_index);
}
答案 0 :(得分:2)
您必须扩展SimpleCursorAdapter并覆盖getView(),对于列表中的每个项目,您可以在其中布置行中的数据。
对于图像,我认为有一个名为BitmapFactory的类,您可以使用它来创建来自URL,路径等的图像。我自己没有使用它,所以不能举一个例子我害怕。
祝你好运!