我正在尝试找到一种为某些用户输入创建弹出屏幕的方法,其中包括单选按钮,editText,按钮。我不想开始一项新活动。 什么是好的选择? AlertDialog? Spinner?弹出菜单? 感谢
答案 0 :(得分:7)
AlertDialog对此没问题。您可以声明一个layout.xml文件,其中包含您需要的所有组件,然后对其进行充气并将其设置为对话框的内容。
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();