android AlertDialog onActivityResult
Bonjour,
Je remarque que l'alertDialog ne fonctionne pas si on appelle la méthode showDialog dans onActivityResult.
Je vous donne le squelette de mon code ; sachez que thumUri et photoPath sont initialisé et comporte les bonnes valeurs dans onActivityResult
Code:
1 2 3 4 5 6
|
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
showDialog(thumbUri,photoPath); |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
@Override
public void onClick(View arg0) {
if (monBoutton.isPressed()) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File("/sdcard/tmp")));
startActivityForResult(i, NEW_IMAGE);
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
private void showDialog(final Uri thumbUri, final String photoPath) {
runOnUiThread(new Runnable() {
@Override
public void run() {
LayoutInflater inflater = (LayoutInflater) GalleryActivity.this
.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Voulez-vous confirmer la sauvegarde de cette photo?");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageURI(thumbUri);
builder = new AlertDialog.Builder(GalleryActivity.this);
builder.setView(layout);
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
}
});
alertDialog = builder.create();
alertDialog.show();
}
}); |