// 刷新图片 @Override public void onResume() { super.onResume(); if (!TextUtils.isEmpty(pathImage)) { Bitmap addbmp = BitmapFactory.decodeFile(pathImage); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("itemImage", addbmp); imageItem.add(map); simpleAdapter = new SimpleAdapter( getActivity(), imageItem, R.layout.item_upload_image_grid, new String[] {"itemImage"}, new int[] {R.id.imageView1}); simpleAdapter.setViewBinder( new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { // TODO Auto-generated method stub if (view instanceof ImageView && data instanceof Bitmap) { ImageView i = (ImageView) view; i.setImageBitmap((Bitmap) data); return true; } return false; } }); mGridView.setAdapter(simpleAdapter); simpleAdapter.notifyDataSetChanged(); // 刷新后释放防止手机休眠后自动添加 pathImage = null; } }
// 获取图片路径 响应startActivityForResult public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // 打开图片 if (resultCode == getActivity().RESULT_OK && requestCode == IMAGE_OPEN) { Uri uri = data.getData(); if (!TextUtils.isEmpty(uri.getAuthority())) { // 查询选择图片 Cursor cursor = getActivity() .getContentResolver() .query(uri, new String[] {MediaStore.Images.Media.DATA}, null, null, null); // 返回 没找到选择图片 if (null == cursor) { return; } // 光标移动至开头 获取图片路径 cursor.moveToFirst(); pathImage = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); } } // end if 打开图片 }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
@Override public void onDestroyView() { super.onDestroyView(); }