1

Friends,

I am unable to set custom view for AlertDialog MultiChoiceItems.

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

builder.setMultiChoiceItems(items.toArray(new CharSequence[items.size()]), selected, this);

ListAdapter adapter = new ArrayAdapter<String>(getContext(), R.layout.spinner, items)
{
    public View getView(int position, View convertView, ViewGroup parent)
    {
        final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (convertView == null)
        {
            convertView = inflater.inflate(R.layout.spinner, null);
        }

        TextView title = (TextView) convertView.findViewById(R.id.aaa);
        title.setText("Yes");

        TextView subtitle = (TextView) convertView.findViewById(R.id.bbb);
        subtitle.setText("KaBooom");

        return convertView;
    }
};

builder.setAdapter(adapter, null);

builder.setOnCancelListener(this);
builder.show();

I read the identical question here Custom listview on AlertDialog multichoice, however I was not able to reproduce it. The MultiChoiceItems replace the default view and the adapter is neglected.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView
    android:id="@+id/aaa"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:textAlignment="inherit"
    android:text="aaa"
    />

<TextView
    android:id="@+id/bbb"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:textAlignment="inherit"
    android:text="bbb"
    />

</RelativeLayout>
Community
  • 1
  • 1
sitilge
  • 3,687
  • 4
  • 30
  • 56

1 Answers1

0

Maybe you should use a dialogfragment

marcel
  • 313
  • 4
  • 10