是否可以在对话框中包含ListView?

时间:2011-10-03 04:24:11

标签: android listview dialog

基本上,我有这个最初由[Fedor] [1]创建的LazyList,我只是想知道是否还有将它放在对话框中。请帮助我,我一直在努力解决这个问题,我真的需要你的帮助。提前谢谢!

在你需要的时候输入他的代码:

    p

            list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,long id) {  



                    if(position == 0){



                        final Dialog dialog = new Dialog(MainPictures.this, R.style.CustomDialogTheme);
                        dialog.setContentView(R.layout.customlayout);
                        dialog.setTitle(null);
                        dialog.setCancelable(true);
                        dialog.show();
                        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); 
                        lp.dimAmount=0.5f;  
                        dialog.getWindow().setAttributes(lp);  
                        dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);



                    }




                    else {
                        System.out.println("Error");
                    }

                    }                                                                                                       
                });


        }






        private String[] mStrings={
                "http://www.urlurl/hi.png",
                "http://www.urlurl/hi.png",

        };
    }

2 个答案:

答案 0 :(得分:0)

对此有一个想法。

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

<强>更新

另一个解决方案可能是创建一个ACtivity并将listView放入其中,并将其主题设为对话框。

阅读本文以了解如何设置主题http://developer.android.com/guide/topics/ui/themes.html

答案 1 :(得分:0)

您必须创建一个包含自定义布局的对话框。例如,使用此布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="400dip"
              android:padding="10dp">
    <ListView android:id="@+id/MyAwesomeList"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"/>
</LinearLayout>

当你在Activity的onCreateDialog()回调中创建对话框时,将它用于这样的对话框:

Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);

dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Dialog");

ListView myList = (ListView) dialog.findViewById(R.id.MyAwesomeList);
// set the list adapter and stuff