3

我正在开发一个应用程序,其中我在AlertDialog. 在某些情况下,会出现对话框,显示其Title和。问题是,当我在列表中添加超过 4 个条目时,设置的对话框消息被列表视图隐藏。无论列表有多长,我都想在消息下方显示列表视图。谁能帮我吗????MessageCustom listview

实施如下:

AlertDialog.Builder builder = new AlertDialog.Builder(xActivity.this);
     builder.setTitle("Title");
     builder.setMessage("Following items are in the List");                 
     final ListView modeList = new ListView(xActivity.this);
     ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(xActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, simpleArray);
     modeList.setAdapter(modeAdapter);
     modeList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
     builder.setView(modeList);
     builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

     public void onClick(DialogInterface arg0, int arg1) {

    // Do Something

    }
}});

final Dialog dialog = builder.create(); 
dialog.show();

任何帮助表示赞赏.... :-)

4

2 回答 2

3

我建议并认为最好的方法是创建自定义对话框而不是预定义的 AlertDialog。创建自己的 xml。

http://developer.android.com/guide/topics/ui/dialogs.html

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Following items are in the List"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ListView
        android:id="@+id/lvList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.15" >
    </ListView>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Yes" />

</LinearLayout>

爪哇

Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_listview);

Button btn = (Button) dialog.findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener(){

    public void onClick(View arg0) {
        dialog.cancel();
        }    
});

dialog.show();
于 2012-12-27T13:38:09.797 回答
0

I suggest using the same manner exposed above, only that instead of using basic Dialog class, the DialogFragment class which is keeps its state when the device's state changes (rotation/keyboard...) Hope it helps... ;)

于 2012-12-27T13:54:34.143 回答