갤러리에서 갤러리의 사진을 가져오고 싶지만 할 수 없습니다. 대화 상자에서 재정의 할 startActivityResult() 메서드를 호출 할 수 없습니다. 누구든지 Dialog에서 그것을 할 수있는 방법을 알고 있습니까?갤러리의 갤러리에서 사진을 어떻게 찍을 수 있습니까? - Android
여기 내 코드입니다. (나는 buttonG.setOnClickListener에서 그것을 할 필요가())
갤러리에서 갤러리의 사진을 가져오고 싶지만 할 수 없습니다. 대화 상자에서 재정의 할 startActivityResult() 메서드를 호출 할 수 없습니다. 누구든지 Dialog에서 그것을 할 수있는 방법을 알고 있습니까?갤러리의 갤러리에서 사진을 어떻게 찍을 수 있습니까? - Android
여기 내 코드입니다. (나는 buttonG.setOnClickListener에서 그것을 할 필요가())
맥락은 무엇입니까 사전 :)에서
public class AddBirthdayDialog extends Dialog {
private Context context;
String name;
String sname;
private int day;
private int month;
private int year;
private byte[] imageByte;
private Bitmap imageBitmap;
private int RESULT_LOAD_IMAGE = 1;
final EditText textName;
final EditText textSname;
final DatePicker birthDate;
private DB myDB;
private SQLiteDatabase database;
private Person person = new Person();
public AddBirthdayDialog(final Context context) {
super(context);
this.context = context;
setCanceledOnTouchOutside(false);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.addbirthday_layout);
myDB = new DB(context);
textName = (EditText) findViewById(R.id.editTextname);
textSname = (EditText) findViewById(R.id.editTextsname);
birthDate = (DatePicker) findViewById(R.id.datePicker);
Button buttonG = (Button) findViewById(R.id.buttonUploadG);
buttonG.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
**//Need to call gallery and take a photo's bitmap or byte[] here.**
}
});
Button buttonC = (Button) findViewById(R.id.buttonUploadC);
buttonC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
Button cancelButton = (Button) findViewById(R.id.cancelbutton);
cancelButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});
Button save = (Button) findViewById(R.id.buttonadd);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
name = textName.getText().toString();
sname = textSname.getText().toString();
day = birthDate.getDayOfMonth();
month = birthDate.getMonth()+1;
year = birthDate.getYear();
final String dayStr = String.valueOf(day);
final String monthStr = String.valueOf(month+1);
final String yearStr = String.valueOf(year);
person.setName(name);
person.setSname(sname);
person.setDay(day);
person.setMonth(month);
person.setYear(year);
person.setDateStr(dayStr + "/" + monthStr + "/" + yearStr);
myDB.addBirthday(person);
if(context instanceof MainActivity)
((MainActivity)context).onResume();
dismiss();
}
});
}
}
감사합니다? 당신의 상황에 활동에서 활동을 시작하고 클래스 내부 상황에 활동
에 onActivityResult를 처리하기 위해이 활동 인 경우, 당신은 할 수 있습니다
@SuppressLint("NewApi")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SELECTED_PICTURE:
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection,
null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(projection[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
selectedImage = BitmapFactory.decodeFile(filePath);
d = new BitmapDrawable(selectedImage);
iv.setBackground(d);
update.setVisibility(View.VISIBLE);
}
break;
}
}
의 onclick 내부 :
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECTED_PICTURE);
전역 변수 :
private static final int SELECTED_PICTURE = 1;
Bitmap selectedImage;