这是我的代码,我试图做,但我不知道我必须添加什么代码来做到这一点。请帮帮我!提前感谢:)
@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();
}
});
}
1条答案
按热度按时间0lvr5msh1#
要显示alertdialog,您需要调用
create()
那么show()
方法定义其属性之后。这意味着在代码中定义警报变量后,设置标题和消息,然后编写alert.create().show()
使用setView()
方法并将布局xml作为参数传递。你可以用
View rootView = LayoutInflater.from(this).inflate(R.layout.custom_snippet, null);
并从中访问您的子视图,如:TextView userName = rootView.findViewById(R.id.userName);