在我的活动中,我从数据库中读出所有uri,然后我将其传递给listview,但是当我点击“全部显示”按钮时,需要花费很多时间来切换到新活动。这里有一些代码,这是将图片放在listview中的代码。
public MyListAdapter() {
super(ShowAllActivity.this, R.layout.item_list_view, posts);
}
/**
* Get a view for each post in the list.
* Uses a default picture if there are no photo. If there is a photo for the post then the photo will be correct rotated.
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View postView = convertView;
if (postView == null) {
postView = getLayoutInflater().inflate(R.layout.item_list_view,
parent, false);
}
Post currentPost = posts.get(position);
TextView name = (TextView) postView.findViewById(R.id.tv_item_name);
TextView title = (TextView) postView
.findViewById(R.id.tv_item_title);
TextView date = (TextView) postView.findViewById(R.id.tv_item_date);
ImageView photo = (ImageView) postView
.findViewById(R.id.iv_item_photo);
name.setText(currentPost.getName());
title.setText(currentPost.getTitle());
date.setText(currentPost.getDate());
Uri photoUri = Uri.parse(currentPost.getPhoto());
Bitmap myBitmap;
try {
Uri selectedImage = photoUri;
String[] filePathColumn = { MediaStore.Images.Media.ORIENTATION };
Cursor cursor = getContentResolver().query(selectedImage, null,
null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
int rotation = cursor.getInt(columnIndex);
cursor.close();
myBitmap = android.provider.MediaStore.Images.Media.getBitmap(
getContentResolver(), photoUri);
Matrix mat = new Matrix();
mat.postRotate(rotation);
Bitmap scaledBitmap;
int scaleFactor = 20;
scaledBitmap = Bitmap
.createScaledBitmap(myBitmap, myBitmap.getWidth()/scaleFactor, myBitmap.getHeight()/scaleFactor, true);
Bitmap bMapRotate = Bitmap.createBitmap(scaledBitmap, 0, 0,
scaledBitmap.getWidth(), scaledBitmap.getHeight(), mat,
true);
photo.setImageBitmap(bMapRotate);
} catch (FileNotFoundException e) {
photo.setImageResource(R.drawable.ic_launcher);
} catch (IOException e) {
// TODO Auto-generated catch block
photo.setImageResource(R.drawable.ic_launcher);
} catch (NullPointerException npe) {
photo.setImageResource(R.drawable.ic_launcher);
}
return postView;
}
}