how to set layout_weight programmatically for alert dialog button?

Posted by Are on Stack Overflow See other posts from Stack Overflow or by Are
Published on 2011-01-05T12:35:02Z Indexed on 2011/01/05 12:53 UTC
Read the original article Hit count: 172

Filed under:

Hi, Iam planing to give create 3 buttons with layout_weight=1, not interested in custom dialog.So I have written below code.It is not working.Always yes button gives me null. Whats wrong in this code?

  AlertDialog dialog= new AlertDialog.Builder(this).create();
            dialog.setIcon(R.drawable.alert_icon);
            dialog.setTitle("title");
            dialog.setMessage("Message");
            dialog.setButton(AlertDialog.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                                                }
            });
            Button yesButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            Log.w("Button",""+yesButton);//here getting null
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f);
            yesButton.setLayoutParams(layoutParams);
            dialog.show();

Regards, Android developer.

© Stack Overflow or respective owner

Related posts about android