1
朋友,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>