1

朋友们,

我无法为 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>
4

1 回答 1

0

也许你应该使用一个对话片段

于 2014-10-27T13:35:03.733 回答