【问题标题】:Android Alert Dialog place Edit Text Before List ViewAndroid Alert Dialog 将 Edit Text Before List View
【发布时间】:2014-12-09 18:32:14
【问题描述】:

我正在创建一个带有列表视图和编辑文本的警报对话框,我已经成功了,但是我希望编辑文本首先出现,然后是列表视图,但输出却相反。

 AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
    builderSingle.setIcon(R.drawable.ic_launcher);
    builderSingle.setTitle("Select Item");
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(1); // 1 is for vertical orientation
    final EditText input = new EditText(this);
    ll.addView(input);
            builderSingle.setNegativeButton("cancel",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    builderSingle.setAdapter(adapter,
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                                        }
            });

    builderSingle.setView(ll);
    AlertDialog alert = builderSingle.create();
    alert.show();

【问题讨论】:

    标签: android user-interface dialog alert


    【解决方案1】:

    对于复合视图,我建议在 XML 中编码布局,然后在对话框构建器代码中进行扩展和设置:

    LayoutInflater inflater = (LayoutInflater)   
    mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // My dialog is a separate class so getting your context may be easier.
    View custView = inflater.inflate(R.custom_layout, null);`
    
    ...
    
    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setTitle(title);
    builder.setIcon(R.drawable.ic_launcher_pro);
    builder.setView(custView);
    

    【讨论】:

      【解决方案2】:

      这可能是默认行为。也许您应该通过在布局中创建自己的 ListView 来更好地控制所有这些,这样您就可以更可预测地放置所有内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-24
        • 2020-01-03
        • 1970-01-01
        • 1970-01-01
        • 2020-06-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多