Android 如何在自定义AlertDialog中将LinearLayout添加到父视图?

Android 如何在自定义AlertDialog中将LinearLayout添加到父视图?,android,android-layout,dialog,Android,Android Layout,Dialog,到目前为止,我已经能够使用以下代码将一些LinearLayout添加到另一个LinearLayout: setContentView(R.layout.view_editscore); ViewGroup container = (ViewGroup) findViewById(R.id.container1); for (String s : PlayersActivity.playersList) { LayoutInflater inflater = (L

到目前为止,我已经能够使用以下代码将一些LinearLayout添加到另一个LinearLayout:

setContentView(R.layout.view_editscore);
    ViewGroup container = (ViewGroup) findViewById(R.id.container1);

    for (String s : PlayersActivity.playersList) {
        LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.edit_duplicate, null);

        TextView tv = (TextView) view.findViewById(R.id.userName);
        tv.setText(s);

        container.addView(view);
    }
然后,我还可以使用以下代码使用R.layout.view\u editscore视图填充自定义AlertDialog:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.editScore);

    LayoutInflater in = getLayoutInflater();

    builder.setView(in.inflate(R.layout.view_editscore, null));
但出于某种原因,当我使用setView将R.layout.view_editscore放入AlertDialog时,它只添加了在我添加每个LinearLayout之前作为外壳的版本

在使用其他线性布局填充视图之前和之后,我都尝试过构建自定义AlertDialog,但这两种方法仍然产生相同的结果


我可能做错了什么?

随后向膨胀的布局添加视图不会改变该布局的xml定义。膨胀版面,将视图添加到其中,然后将该版面对象设置为内容视图。好的,可以了。谢谢你的帮助。我仍在试图准确地理解通货膨胀到底是什么。如果你的代码与你在文章第二部分中所展示的一样,那就不是你正在做的。在.inflateR.layout.view_editscore中,null正在对布局的新实例进行充气,而不添加任何视图。将其从setView方法中去掉,将其指定给ViewGroup变量,将视图添加到该ViewGroup,然后将setView与ViewGroup一起使用。