안녕하세요~!! 초보 앱 개발자 입니다!@@
요즘 질문이 잦아 죄송하네요 ㅜㅜ
오늘 드릴 질문은 다이얼로그 안에서 이미지를 가져오는 것입니다...!!!
제가 다이얼로그에 쓰일 layout에 버튼을 넣고 그리고 이미지 뷰하나를 놓고
버튼을 클릭하면 갤러리 혹은 카메라에서 이미지를 가져와 이미지 뷰에 넣는 기능을 하려고 합니다,
이 기능이 다이얼로그가 아닌 그냥 activity 상에서는 잘 돌아 가는데 다이얼로그 안에서는 왜 안되는지 몰라서
이렇게 질문 드립니다 ㅜㅜ 오늘도 명쾌한 답으로 저를 구제해 주세요....!!!!
소스 코드 첨부 하겠습니다...!!!!
--------------------------------------------------------------------------------------------------------------------------------
case DIALOG_1:
final LinearLayout linear = (LinearLayout)inflater.inflate(R.layout.user_view, null);
image = (ImageView) findViewById(R.id.activity_main_image);
button = (Button) findViewById(R.id.button01);
button.setOnClickListener(buttonListener);
return new AlertDialog.Builder(main_activity.this)
.setTitle("울라라")
.setView(linear)
.setPositiveButton("확인", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
EditText ed_name = (EditText)linear.findViewById(R.id.make_name);
EditText ed_company = (EditText)linear.findViewById(R.id.make_company);
EditText ed_phone = (EditText)linear.findViewById(R.id.make_phone);
EditText ed_address = (EditText)linear.findViewById(R.id.make_address);
EditText ed_rank = (EditText)linear.findViewById(R.id.make_rank);
insert_item(ed_name.getText().toString(),ed_company.getText().toString(),ed_rank.getText().toString(), ed_phone.getText().toString(),ed_address.getText().toString());
reset_list();
ed_name.requestFocus();
ed_name.setText("");
ed_company.setText("");
ed_phone.setText("");
ed_address.setText("");
ed_rank.setText("");
}
})
.setNegativeButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
EditText ed_name = (EditText)linear.findViewById(R.id.make_name);
EditText ed_company = (EditText)linear.findViewById(R.id.make_company);
EditText ed_phone = (EditText)linear.findViewById(R.id.make_phone);
EditText ed_address = (EditText)linear.findViewById(R.id.make_address);
EditText ed_rank = (EditText)linear.findViewById(R.id.make_rank);
ed_name.requestFocus();
ed_name.setText("");
ed_company.setText("");
ed_phone.setText("");
ed_address.setText("");
ed_rank.setText("");
}
})
.create();
여기서 다이얼 로그 빠져 나온 뒤에 activity 상에 아래와 같은 소스 넣었습니다.
private View.OnClickListener buttonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// Determine Uri of camera image to save.
FileUtils.createDefaultFolder(main_activity.this);
final File file = FileUtils.createFile(FileUtils.IMAGE_FILE);
outputFileUri = Uri.fromFile(file);
// Camera.
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
final Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
// Filesystems
// galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // To allow file managers or any other app that are not gallery app.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Image");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { captureIntent });
startActivityForResult(chooserIntent, YOUR_SELECT_PICTURE_REQUEST_CODE);
}
};