Question

I'm building a simple AlertDialog with custom layout from XML. Here is how it's supposed to look (taken from Eclipse): It's simply 4 columns:

enter image description here

Here is the xml of the image above:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="1.0" >

    <ImageView
        android:id="@+id/colorpicker_dialog_color1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25"
        android:background="#FFF"
        android:tag="0xFFF" />

    <ImageView
        android:id="@+id/colorpicker_dialog_color2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25"
        android:background="#FFDD66"
        android:tag="0xFFDD66" />

    <ImageView
        android:id="@+id/colorpicker_dialog_color3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25"
        android:background="#66CCFF"
        android:tag="0x66CCFF" />

    <ImageView
        android:id="@+id/colorpicker_dialog_color4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25"
        android:background="#B6C0D2"
        android:tag="0xB6C0D2" />

</LinearLayout>

Here is the code of the costume Alert Dialog:

public void showColorPickerDialog() {
        LayoutInflater inflater = LayoutInflater.from(this);
        View layout = inflater
                .inflate(R.layout.color_picker_dialog, null);

        ImageView clr1 = (ImageView) layout
                .findViewById(R.id.colorpicker_dialog_color1);

        clr1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // .. code
            }
        });

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("cccc");

        builder.setView(layout)
                .setCancelable(true)
                .setPositiveButton("ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        }).show();

    }

The problem is that in my dialog I dont see any column.

Was it helpful?

Solution

Try using Views instead of ImageViews in your layout. The problem using ImageViews in your case is that since you do not specify the src attribute for the ImageView, it will display a 0x0-sized image, which leaves your views invisible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top