제가 이미지뷰들을 레이아웃에 몇개 나열해놓고 각각 이미지 클릭시 갤러리를 열어서 이미지를 불러와서
클릭한 이미지 칸에 넣어주는 코딩을 하려고하는데
imageView1을 눌러서 가져온다고친다면 onActivityResult에 imageView1.setImageBitmap을 넣어주게된다면
각각 imageView2 ,3...이렇게 많아지면 코드가너무길어져서 switch를 쓰든 어떻게든 해보고싶은데
onActivityResult는 어떻게해줘야 될지 너무 답이안나오네요 ㅠㅠ
@Override
public void onClick(View view) {
Intent intent=null;
if (Build.VERSION.SDK_INT<19){
intent=new Intent(Intent.ACTION_GET_CONTENT);
}else{
intent=new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
}
intent.setType("image/*");
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB){
intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
}
startActivityForResult(intent, 100);
}
@Override
public void onActivityResult(int requestCode, int resultcode,Intent data) {
if (resultcode == Activity.RESULT_OK) {
Uri photoUri = data.getData();
Log.d("GALLERY", photoUri.toString());
String filePath = FileUtils.getPath(this, photoUri);
Log.d("FILE_PATH", filePath);
imageView1.setImageBitmap(null);
if (bmp != null) {
bmp.recycle();
bmp = null;
}
bmp = PhotoHelper.getInstance().getThumb(this, filePath);
imageView1.setImageBitmap(bmp);
imageView1.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
대략 저의 노답 코딩은 이렇습니다... 어디에 switch를 줘야하는건지 intent로 불러와서하는 코딩은 처음이라 막막하네요 조언좀 부탁드리겠습니다!ㅠㅠ 저의 머리로는 이틀이 넘게고민중이에용 ....ㅠ