Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击弹出菜单中的项目时,如何为AlertDialog充气布局?_Java_Android_Alert - Fatal编程技术网

Java 单击弹出菜单中的项目时,如何为AlertDialog充气布局?

Java 单击弹出菜单中的项目时,如何为AlertDialog充气布局?,java,android,alert,Java,Android,Alert,这是我试图做的代码,但我不知道我必须添加什么代码才能做到这一点。 请帮帮我! 提前感谢:) 要显示AlertDialog,您需要在定义其属性后调用create()然后调用show()方法。 这意味着在定义了警报变量后,在代码中设置标题和消息,然后编写此alert.create().show() 使用setView()方法并将布局xml作为参数传递 您可以使用View rootView=LayoutInflater.from(this).inflate(R.layout.custom_snippe

这是我试图做的代码,但我不知道我必须添加什么代码才能做到这一点。 请帮帮我! 提前感谢:)


要显示AlertDialog,您需要在定义其属性后调用
create()
然后调用
show()
方法。 这意味着在定义了警报变量后,在代码中设置标题和消息,然后编写此
alert.create().show()

使用
setView()
方法并将布局xml作为参数传递


您可以使用
View rootView=LayoutInflater.from(this).inflate(R.layout.custom_snippet,null)
并从中访问您的子视图,如:
TextView userName=rootView.findviewbyd(R.id.userName)

我创建acustom版面是为了将其视为alretit的作品,但如何在自定义版面中充气?
@Override
public void onBindViewHolder(@NonNull HalakaViewHolder holder, int position) {
    holder.bind(halakat.get(position));
    holder.imgbtn_more.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            PopupMenu popup = new PopupMenu(holder.itemView.getContext(), view);
            popup.getMenuInflater().inflate(R.menu.halaka_more_menu, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    int id = menuItem.getItemId();
                    switch (id) {
                        case R.id.menu_more_halaka_tadel:
                            Toast.makeText(holder.itemView.getContext(), ""+menuItem.getTitle(), Toast.LENGTH_SHORT).show();
                            final AlertDialog.Builder alert=new AlertDialog.Builder(holder.itemView.getContext());
                            break;
                        case R.id.menu_more_halaka_delete:
                            Toast.makeText(holder.itemView.getContext(), ""+menuItem.getTitle(), Toast.LENGTH_SHORT).show();
                            break;
                    }
                    return true;
                }
            });
            popup.show();
        }
    });
}