Android警报对话框在列表视图之前编辑文本

时间:2014-12-09 18:32:14

标签: android user-interface dialog alert

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

 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();

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

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