0

was working on an alertdialog with checkbox something like this

CharSequence[] items = {"Google", "Apple", "Microsoft", "Google", "Apple", "Microsoft"};
boolean[] itemsChecked = new boolean[items.length];

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btn = (Button) findViewById(R.id.button1);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(0);
        }
    });
}

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 0:
        ContextThemeWrapper cw = new ContextThemeWrapper( this, R.style.AlertDialogTheme );
        return new AlertDialog.Builder(cw/*this*/) //tried cw, but of no use
        .setIcon(R.drawable.ic_launcher)
        .setTitle("Dialog with simple text")
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                for (int i = 0; i < items.length; i++) {
                if (itemsChecked[i]) {
                    Toast.makeText(getBaseContext(), items[i] + " checked!", Toast.LENGTH_LONG).show();
                }
            }
            }
        })
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_LONG).show();
            }
        })
        .setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                Toast.makeText(getBaseContext(), items[which] + (isChecked ? "checked!" : "unchecked!"), Toast.LENGTH_SHORT).show();
            }
        })
        .create();

    }

    return null;
}

but width and height is totally out of my control, did tried with changing theme like

    <style name="AlertDialogTheme" parent="android:Theme.Dialog">
         <item name="android:textSize">14sp</item>
        <item name="android:width">60dp</item>
        <item name="android:height">100dp</item>

</style>

changed it slightly, the result is awful, found this interesting, but i guess my scenario is different (may be, the builder variable is out of my reach, to use it)

Community
  • 1
  • 1
x-code
  • 608
  • 1
  • 10
  • 30

0 Answers0