Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return data from Custom Dialog

Tags:

android

I'm calling a custom dialog thusly

        CustomDialog dialog = new CustomDialog(this);
        dialog.setCancelable(true);
        dialog.show();

Now, if I have a bunch of buttons in the dialog, how do I return the user's choice when I dismiss() the dialog?

like image 799
Joren Avatar asked Nov 05 '22 07:11

Joren


1 Answers

You can refer this link http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

Example:

Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);

dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Dialog");

TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

You can also use alert dialog for custom

AlertDialog.Builder builder;
AlertDialog alertDialog;


Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater)   Context.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("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
like image 55
krunal shah Avatar answered Nov 09 '22 14:11

krunal shah