Android AlertDialog MultiChoiceItems未显示自定义视图

时间:2014-10-27 13:24:11

标签: android android-alertdialog multichoiceitems

我无法为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();

我在这里阅读了相同的问题Custom listview on AlertDialog multichoice,但我无法重现它。 MultiChoiceItems替换默认视图,忽略适配器。

<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>

1 个答案:

答案 0 :(得分:0)

也许你应该使用dialogfragment