Android:以编程方式将ListView设置为Dialog内容

| 我究竟做错了什么?我收到一个没有内容的空白对话框。码:
@Override
protected Dialog onCreateDialog(int id, Bundle b) {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
    switch(id) {
        case DIALOG_COLOR_MODE:
        {
            LinearLayout layout = new LinearLayout(this);
            LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            layout.setLayoutParams(lllp);

            ListView modeList = new ListView(this);
            Dialog dialog = new Dialog(this);

            TextView layoutBright = new TextView(this);
            TextView layoutNormal = new TextView(this);

            layoutBright.setText(\"Bright Mode\");
            layoutNormal.setText(\"Normal Mode\");

            modeList.addFooterView(layoutBright);
            modeList.addFooterView(layoutNormal);

            layout.addView(modeList);

            dialog.setContentView(layout);

            return dialog;
        }
[...]
    
已邀请:
        解:
Dialog dialog = new Dialog(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(\"Select Color Mode\");

ListView modeList = new ListView(this);
String[] stringArray = new String[] { \"Bright Mode\", \"Normal Mode\" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
modeList.setAdapter(modeAdapter);

builder.setView(modeList);
dialog = builder.create();
但是说实话,使用AlertDialog.Builder.setItems()是一个更好的解决方案。     

要回复问题请先登录注册