Note that there are some explanatory texts on larger screens.

plurals
  1. POAdjusting size of custom dialog box in android
    primarykey
    data
    text
    <p>I am building an custom alert dialog box for my application i have written the code and its working but the only problem is its size it is not adjusting according to my content in dialog box. below is my code:</p> <pre><code>public class CustomDialogBoxActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.Button01main); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub final Dialog myDialog = new Dialog(CustomDialogBoxActivity.this); myDialog.setContentView(R.layout.dialog_sms_layout); myDialog.setTitle("Select any one"); Button ok = (Button)myDialog.findViewById(R.id.buttonOK); final RadioGroup radioGrp = (RadioGroup)myDialog.findViewById(R.id.radioGroupSmsDialog); final CheckBox mob1 = (CheckBox)myDialog.findViewById(R.id.checkBoxMob1); final CheckBox mob2 = (CheckBox)myDialog.findViewById(R.id.checkBoxMob2); mob1.setText("9029691986"); mob2.setText("99263911766"); ok.setOnClickListener(this); ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(mob1.isChecked() &amp;&amp; mob2.isChecked()) { if(radioGrp.getCheckedRadioButtonId() == R.id.radioSms) { String[] phoneArray = {mob1.getText().toString(),mob2.getText().toString()}; Log.v("MOB1",mob1.getText().toString()); Log.v("MOB2",mob2.getText().toString()); Log.v("Mobile No", ""+phoneArray.toString()); sendSms("SMS Message",phoneArray); }else if(radioGrp.getCheckedRadioButtonId() == R.id.radioBusinessCard) { String[] phoneArray = {mob1.getText().toString(),mob2.getText().toString()}; Log.v("MOB1",mob1.getText().toString()); Log.v("MOB2",mob2.getText().toString()); Log.v("Mobile No", ""+phoneArray.toString()); sendSms("SMS Business Card",phoneArray); } }else if(mob1.isChecked() &amp;&amp; !mob2.isChecked()) { if(radioGrp.getCheckedRadioButtonId() == R.id.radioSms) { String[] phoneArray = {mob1.getText().toString()}; Log.v("MOB1",mob1.getText().toString()); Log.v("Mobile No", ""+phoneArray.toString()); sendSms("SMS Message",phoneArray); }else if(radioGrp.getCheckedRadioButtonId() == R.id.radioBusinessCard) { String[] phoneArray = {mob1.getText().toString()}; Log.v("MOB1",mob1.getText().toString()); Log.v("Mobile No", ""+phoneArray.toString()); sendSms("SMS Business Card",phoneArray); } }else if(!mob1.isChecked() &amp;&amp; mob2.isChecked()) { if(radioGrp.getCheckedRadioButtonId() == R.id.radioSms) { String[] phoneArray = {mob2.getText().toString()}; Log.v("MOB2",mob2.getText().toString()); Log.v("Mobile No", ""+phoneArray.toString()); sendSms("SMS Message",phoneArray); }else if(radioGrp.getCheckedRadioButtonId() == R.id.radioBusinessCard) { String[] phoneArray = {mob2.getText().toString()}; Log.v("MOB2",mob2.getText().toString()); Log.v("Mobile No", ""+phoneArray.toString()); sendSms("SMS Business Card",phoneArray); } }else if(!mob1.isChecked() &amp;&amp; !mob2.isChecked()) { Toast.makeText(getApplicationContext(), "Select atleast one number", Toast.LENGTH_SHORT).show(); } } }); myDialog.show(); } }); } public void sendSms(String message,String[] phoneNumber) { Intent smsIntent = new Intent(Intent.ACTION_VIEW); smsIntent.setData(Uri.parse("sms:")); smsIntent.putExtra("sms_body", message); smsIntent.putExtra("address", phoneNumber); startActivity(smsIntent); } } </code></pre> <p>This is the <a href="http://i42.tinypic.com/2rw4xw3.png">output</a> that i'm getting on button click </p> <p>This is my main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is my main activity, from here, I want to display a dialog, after the user clicked the button below this text." /&gt; &lt;Button android:id="@+id/Button01main" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show Dialog" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>and this is my dialog_sms_layout</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;RadioGroup android:id="@+id/radioGroupSmsDialog" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;RadioButton android:id="@+id/radioSms" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="SMS" /&gt; &lt;RadioButton android:id="@+id/radioBusinessCard" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Card" /&gt; &lt;/RadioGroup&gt; &lt;CheckBox android:id="@+id/checkBoxMob1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="Primary" /&gt; &lt;CheckBox android:id="@+id/checkBoxMob2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Secondary" /&gt; &lt;Button android:id="@+id/buttonOK" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="OK" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>I want to adjust the dialog box size please help. thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload