gpt4 book ai didi

android - 使用自定义布局时 AlertDialog 按钮不可见

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:11:46 25 4
gpt4 key购买 nike

我想要弹出窗口中的自定义布局,所以我使用了警报对话框。由于弹出窗口中的 subview 数量是动态决定的,所以我使用了 ScrollView。现在转折点来了,当没有剩余空间并且滚动起作用时,正负按钮变得不可见。下面是代码:

AlertDialog.Builder dialog;
dialog = new AlertDialog.Builder(this);

dialog.setMessage("Please enter below parameters");

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);

LinearLayout rootLayout = new LinearLayout(this);
rootLayout.setOrientation(LinearLayout.VERTICAL);

ScrollView scrollView = new ScrollView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(50, 0, 50, 0);


try {
JSONArray data = new JSONArray(parameters);
String toastDaata = "";
for (int i = 0; i < data.length(); i++) {
JSONObject parameter = data.getJSONObject(i);
String sources = parameter.getString("sources");
String name = parameter.getString("name");
String mandatory = parameter.getString("mandatory");
toastDaata = toastDaata + "\n" + name + ":" + mandatory;

EditText editText$name = new EditText(this);
editText$name.setHint(name);
editText$name.setLayoutParams(params);
TextInputLayout textInputLayout = new TextInputLayout(this);
textInputLayout.setLayoutParams(params);
textInputLayout.addView(editText$name, params);
layout.addView(textInputLayout);

}
flowDescription.setText(toastDaata);
Toast.makeText(this, toastDaata, Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}

scrollView.addView(layout);
rootLayout.addView(scrollView);


dialog.setView(rootLayout);
dialog.setNegativeButton("Cancel", null);
dialog.setPositiveButton("Go", null);

dialog.show();

enter image description here enter image description here

根据图像,当需要滚动时它会隐藏按钮。

最佳答案

试试这个..它对我有用...

AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); 
LinearLayout rootLayout = new LinearLayout(this);
rootLayout.setOrientation(LinearLayout.VERTICAL);
ScrollView scrollView = new ScrollView(MainActivity.this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < 20; i++) {
EditText editText$name = new EditText(this);
editText$name.setHint("Test");
TextInputLayout textInputLayout = new TextInputLayout(this);
textInputLayout.addView(editText$name);
layout.addView(textInputLayout);
}
scrollView.addView(layout);
rootLayout.addView(scrollView);
alertDialog.setNegativeButton("Cancel", null);
alertDialog.setPositiveButton("Go", null);
alertDialog.setView(rootLayout);
alertDialog.show();

与您异常(exception)的输出相同..

enter image description here

关于android - 使用自定义布局时 AlertDialog 按钮不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48298340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com