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

Android 是否可以在对话框中包含ListView?,android,listview,dialog,Android,Listview,Dialog,基本上,我有这个懒散列表,它最初是由[Fedor][1]创建的,我只是想知道是否有任何方法可以将它放在对话框中。请帮帮我,我已经挣扎了好几天试图弄明白这一点,我真的需要你的帮助。提前谢谢 这是您需要时的代码: p list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View ar

基本上,我有这个懒散列表,它最初是由[Fedor][1]创建的,我只是想知道是否有任何方法可以将它放在对话框中。请帮帮我,我已经挣扎了好几天试图弄明白这一点,我真的需要你的帮助。提前谢谢

这是您需要时的代码:

    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",

        };
    }
p
list.setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView arg0,视图arg1,int位置,长id){
如果(位置==0){
最终对话框=新对话框(MainPictures.this,R.style.CustomDialogTheme);
setContentView(R.layout.customlayout);
对话框.setTitle(空);
对话框。可设置可取消(true);
dialog.show();
WindowManager.LayoutParams lp=dialog.getWindow().getAttributes();
lp.dimAmount=0.5f;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG\u BLUR\u BEHIND);
}
否则{
System.out.println(“错误”);
}
}                                                                                                       
});
}
私有字符串[]mStrings={
"http://www.urlurl/hi.png",
"http://www.urlurl/hi.png",
};
}
请对此大发雷霆

更新:

另一个解决方案是创建一个活动,将listView放入其中,并将其主题设置为对话框

阅读此文,了解如何设置主题

对此进行一番探讨

更新:

另一个解决方案是创建一个活动,将listView放入其中,并将其主题设置为对话框


阅读此文了解如何设置主题,您必须创建一个带有自定义布局的对话框。例如,使用这个布局

<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>

您必须创建具有自定义布局的对话框。例如,使用这个布局

<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>


我知道如何创建基本对话框,但不知道如何在dialog@Lean.. 您可以将列表添加到对话框中,它看起来就像ListView,向下滚动并阅读整个文档。这里没有ListView。请帮忙me@Leon.. 没有listView,但您可以将字符串列表添加到AlertDialog,它看起来就像AlertDialog。查看我的更新编辑。我知道如何创建基本对话框,但不知道如何在dialog@Lean.. 您可以将列表添加到对话框中,它看起来就像ListView,向下滚动并阅读整个文档。这里没有ListView。请帮忙me@Leon.. 没有listView,但您可以将字符串列表添加到AlertDialog,它看起来就像AlertDialog。查看我的编辑以进行更新..谢谢你的帮助,但是当我使用Fedor的ListView时,它会给我这个错误“构造函数LazyAdapterWallpaper(new AdapterView.OnItemClickListener(){},String[])未定义”谢谢你的帮助,但是当我使用Fedor的ListView时,它会给我这个错误“构造函数LazyAdapterWallpaper(new AdapterView.OnItemClickListener(){},String[])未定义”是否希望“mStrings”出现在listView中..?是的,但正如我之前所说,它总是给我一个错误实际上,这整段代码就是我希望出现在我的dialog@Lean然后将此xml标记添加到活动标记下“看看我上面的代码,我简化了一点。你想让“mStrings”出现在listView中吗?是的,但就像我之前说的,它总是给我一个错误事实上,这整段代码就是我想出现在我的dialog@Lean然后在您的活动标记“”下以xml形式添加此标记。请查看上面的代码,我将其简化了一点。