There is an application in it CardView is displayed on top of RecyclerView . On CardView there is an element which, by pressing, knocks out a menu. It is necessary that AlertDialog by clicking on the menu AlertDialog , tried to do this:
DialogFragment editDialog = new AlertDialogEdit(); editDialog.show(getFragmentManager(), " "); The problem is that in the adapter class where all this is prescribed for me, the studio does not want to create a getFragmentManager() method getFragmentManager() studio allocates it in red, although the same method in any other class is called normally. Please explain what may be wrong.
Adapter Code:
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> { private List<RecyclerItem> listItems; private Activity activity; DialogFragment editDialog = new AlertDialogEdit(); public RecyclerAdapter( Activity activity, List<RecyclerItem> listItems) { this.activity = activity; this.listItems = listItems; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item, parent, false); return new ViewHolder(v); } @Override public void onBindViewHolder(final ViewHolder holder, final int position) { final Context context = holder.itemView.getContext();; holder.txtTitle.setText(listItems.get(position).getTitle()); holder.txtDescription.setText(listItems.get(position).getDescription()); holder.txtOptionDigit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popupMenu = new PopupMenu(context, holder.txtOptionDigit); popupMenu.inflate(R.menu.option_menu); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.mnu_item_edit: editDialog.show(getFragmentManager(), ""); Toast.makeText(context, "Edited", Toast.LENGTH_LONG).show(); break; case R.id.mnu_item_delete: listItems.remove(position); notifyDataSetChanged(); Toast.makeText(context, "Deleted", Toast.LENGTH_LONG).show(); break; default: break; } return false; } }); popupMenu.show(); } }); } @Override public int getItemCount() { return listItems.size(); } public class ViewHolder extends RecyclerView.ViewHolder{ public TextView txtTitle; public TextView txtDescription; public TextView txtOptionDigit; public ViewHolder(View itemView) { super(itemView); txtTitle = (TextView) itemView.findViewById(R.id.txtTitle); txtDescription = (TextView) itemView.findViewById(R.id.txtDescription); txtOptionDigit = (TextView) itemView.findViewById(R.id.txtOptionDigit); } }} The code for the class responsible for AlertDialog:
public class AlertDialogEdit extends DialogFragment implements View.OnClickListener{ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.edit_dialog, null); v.findViewById(R.id.button).setOnClickListener(this); v.findViewById(R.id.button2).setOnClickListener(this); return v; } public void onClick(View v) { switch (v.getId()) { case R.id.button: Log.d("Log", "Ok"); dismiss(); break; case R.id.button2: Log.d("Log", "Cancel"); dismiss(); break; default: break; } }}