[英]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.