Я хочу создать всплывающее меню с параметрами редактирования и удаления в представлении карты. Я пробовал приведенный ниже код, но я принудительно закрываюсь в popup.show();
с фатальным исключением onclick
из imageview
. Что мне сделать, чтобы создать всплывающее меню на cardview
?
public class ShipRecyclerAdapter extends RecyclerView.Adapter<ShipRecyclerAdapter.ViewHolder> {
public static final String PRODUCTID = "PRODUCTID";
public static final String PRODUCTNAME = "PRODUCTNAME";
List<CustDatabaseModel> dbCustList;
static Context context;
public ImageView btndots;
ShipRecyclerAdapter(Context context, List<CustDatabaseModel> dbCustList ){
this.dbCustList = new ArrayList<CustDatabaseModel>();
this.context = context;
this.dbCustList = dbCustList;
}
@Override
public ShipRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.address_list, null);
// create ViewHolder
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
@Override
public void onBindViewHolder(ShipRecyclerAdapter.ViewHolder holder, final int position) {
holder.address.setText(dbCustList.get(position).getaddress());
holder.city.setText(dbCustList.get(position).getcity());
holder.state.setText(dbCustList.get(position).getstate());
holder.zipcode.setText(dbCustList.get(position).getzip());
final String adr=dbCustList.get(position).getaddress().toString();
holder.btndots.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
PopupMenu popup = new PopupMenu(context, btndots);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Intent i;
if ((item.getTitle().toString()).equalsIgnoreCase("Edit")) {
Toast.makeText(ShipRecyclerAdapter.context, "you have clicked Menu image ", Toast.LENGTH_LONG).show();
} else if ((item.getTitle().toString()).equalsIgnoreCase("Delete")) {
Toast.makeText(ShipRecyclerAdapter.context, "you have clicked Menu image ", Toast.LENGTH_LONG).show();
}
return true;
}
});
popup.show();
}
});
//closing the setOnClickListener method
}
@Override
public int getItemCount() {
return dbCustList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView state,address,city,zipcode;
public ImageView btndots;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
address = (TextView) itemLayoutView.findViewById(R.id.textViewAddress);
city = (TextView)itemLayoutView.findViewById(R.id.textViewCity);
zipcode = (TextView)itemLayoutView.findViewById(R.id.textViewZipcode);
state = (TextView)itemLayoutView.findViewById(R.id.textViewState);
this.btndots = (ImageView)itemLayoutView.findViewById(R.id.cmenu);
}
}
}`