I have 2 classes, MainActivity and RecyclerAdapter In MainActivity there is a pop-up dialog:

public void DialogClick(View view) { Log.d(TAG, String.valueOf(view.getTag())); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle((CharSequence) mDataSet.get(1)) .setMessage((CharSequence) mDataSet1.get(1)) .setCancelable(false) .setNegativeButton("закрыть", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } 

In which I want information to appear from the database. But in order to understand on which RecyclerView element the button was pressed, I need to use SetTeg and GetTeg, as I understood. But he gives out a null. Here is the RecyclerAdapter:

 @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.recycler_item, parent, false); ViewHolder vh = new ViewHolder(v); v.setTeg(vh); return vh; } 

    1 answer 1

    Tag here is not needed. In the adapter, you need to hang up the click listener in onBindViewHolder and show a dialog in it that will take data for display from the list of data displayed by the adapter. Because in onBindViewHolder there is a position argument, then you will know exactly which element of the list to display in the dialog.