简体   繁体   English

当我单击弹出菜单中的项目时,如何为 AlertDialog 扩大布局?

[英]How can i inflat layout for AlertDialog when i click item in popup menu?

This my code i try to do but i don't know what the code i must added to do that.这是我尝试做的代码,但我不知道必须添加什么代码才能做到这一点。 plesae help me!请帮帮我! Thanks in advance :)提前致谢 :)

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

To show an AlertDialog you need to call create() then show() methods after you define its properties.要显示 AlertDialog,您需要在定义其属性后调用create() show()方法。 That means in your code after you define the alert variable, set the title and message then write this alert.create().show()这意味着在定义 alert 变量后的代码中,设置标题和消息,然后编写此alert.create().show()

use setView() method and pass your layout xml as a parameter.使用setView()方法并将您的布局 xml 作为参数传递。

You can use View rootView = LayoutInflater.from(this).inflate(R.layout.custom_snippet, null);您可以使用View rootView = LayoutInflater.from(this).inflate(R.layout.custom_snippet, null); and access your child views from it like: TextView userName = rootView.findViewById(R.id.userName);并从中访问您的子视图,例如: TextView userName = rootView.findViewById(R.id.userName);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我单击列表视图(android studio)中的项目时,如何创建要显示的弹出菜单? - How can I create a popup menu to be shown when I click on an item in listview(android studio)? 单击一个按钮,将启动一个弹出菜单,然后单击一个弹出菜单项,然后所选项目将显示在 android 工作室的按钮文本上 - click on a button, a popup menu will start, and then I click on a popup menu item then selected item will show on buttontext in android studio 如何加粗AlertDialog中使用的CharSequence中的一项? - How can I bold one item of a CharSequence used in an AlertDialog? 当我单击 AlertDialog 项目时,关闭并再次打开警报对话框时,单选组不会保持打开状态 - When I click on AlertDialog item, the radio group not stay ON when close and open alert dialog again 当我单击回收站视图中的项目时,我可以使用导航抽屉作为下拉菜单吗? - Can i use a navigation drawer as a dropdown menu when i click on an item in a recyclerview? 如何在操作栏菜单上单击打开编辑文本弹出窗口 - How do i open an edit text popup on actionbar menu click 如何在Eclipse的new-> MyNewMenu上单击鼠标右键,添加弹出菜单? - how can I add popup menu in right-click new->MyNewMenu on eclipse? 从列表中选择项目时如何使用按钮打开弹出窗口?-Android应用程序中 - How can I open a popup with a button when i select an item from a list?-in an android application 带有 actionLayout 的 NavigationView 菜单项。 如何为每个项目设置这些动作布局的属性? - NavigationView menu items with actionLayout. How can I set those action layout's attribute for each item? 单击项目时,使ActionBar上的菜单保持打开状态 - Make menu on ActionBar stay open when I click on an item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM