Just wondering how I would dismiss the dialog box when an option is selected.
Here is the code
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.launch_voip_call) {
Utils.startCall(this, contact);
return true;
}
else if(item.getItemId() == R.id.launch_attachment){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setCancelable(true);
View choiceView = getLayoutInflater().inflate(R.layout.dialog_image_source_chooser, null);
ImageButton cameraButton = (ImageButton) choiceView.findViewById(R.id.cameraButton);
ImageButton galleryButton = (ImageButton) choiceView.findViewById(R.id.galleryButton);
cameraButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent cameraIntent = new Intent(SingleConversationActivity.this, CameraActivity.class);
cameraIntent.putExtra("EXTRA_CONTACT_JID", contact.getJid());
startActivity(cameraIntent);
}
});
yourDialogInstance.dismiss();
https://developer.android.com/reference/android/app/Dialog.html
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(YourActivity.this);
LayoutInflater inflater = YourActivity.this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.dialog_image_source_chooser, null);
dialogBuilder.setView(dialogView);
ImageButton cameraButton = (ImageButton) dialogView.findViewById(R.id.cameraButton);
ImageButton galleryButton = (ImageButton) dialogView.findViewById(R.id.galleryButton);
final AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
cameraButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
Intent cameraIntent = new Intent(SingleConversationActivity.this, CameraActivity.class);
cameraIntent.putExtra("EXTRA_CONTACT_JID", contact.getJid());
startActivity(cameraIntent);
}
});
use alertDialog.dismiss()
inside onClick()
method.
also, to show the dialog, alertDialog.show()
See this answer
Try adding dialogBuilder.dismiss();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.