public void onActivityResult(int requestCode, int resultCode, Intent data) { HideImaShow(); File file = null; if (resultCode == Activity.RESULT_OK) { if (requestCode == R.id.resource_take) { file = temFile; imgList.add(file); } else if (requestCode == R.id.resource_pick) { Uri uri = data.getData(); if (uri.getScheme().equals("content")) { file = new File(SystemMethodUtil.changeURItoPath(uri, context)); if (file.getAbsolutePath().toLowerCase().endsWith(".jpg")) { imgList.add(file); } else { Toast.makeText(context, "不支持的图片格式", Toast.LENGTH_SHORT).show(); } } else if (uri.getScheme().equals("file")) { file = new File(uri.getEncodedPath()); if (file.getAbsolutePath().toLowerCase().endsWith(".jpg")) { imgList.add(file); } else { Toast.makeText(context, "不支持的图片格式", Toast.LENGTH_SHORT).show(); } } } } notifyAdapter(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = LayoutInflater.from(context).inflate(R.layout.media_list_item, null); ImageView imageView = (ImageView) view.findViewById(R.id.media_list_item_img); imageView.setImageBitmap( SystemMethodUtil.compressBitmap(imgList.get(position).getAbsolutePath())); return view; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView = new ImageView(context); imageView.setImageBitmap( SystemMethodUtil.compressBitmap(imgList.get(position).getAbsolutePath())); imageView.setScaleType(ScaleType.FIT_XY); imageView.setLayoutParams( new android.widget.Gallery.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); return imageView; }