【问题标题】:Android AlertDialog MultiChoiceItems not showing custom viewAndroid AlertDialog MultiChoiceItems 不显示自定义视图
【发布时间】:2014-10-27 21:35:03
【问题描述】:

朋友们,

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

【问题讨论】:

    标签: android android-alertdialog multichoiceitems


    【解决方案1】:

    也许你应该使用dialogfragment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      相关资源
      最近更新 更多