3

にリストが入力されているアプリケーションに取り組んでいますAlertDialog。あるイベントでは、ダイアログが表示され、そのTitleMessageおよびが表示されますCustom listview。問題は、リストに4つを超えるエントリを追加すると、設定されているダイアログのメッセージがリストビューによって非表示になることです。リストの長さに関係なく、メッセージの下にリストビューを表示したいと思います。誰かが私を助けることができますか????

実装は次のとおりです。

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

上で公開したのと同じ方法を使用することをお勧めします、基本Dialogクラスを使用する代わりに、デバイスの状態が変化したときにその状態を保持するDialogFragmentクラス (回転/キーボード...) が役立つことを願っています... ;)

于 2012-12-27T13:54:34.143 に答える