access a variable from RecyclerView#Adapter class
<p>I have a class extends RecyclerView#Adapter called <code>RecordAdapter</code>. I implement OnClickListener for my icon in the list for delete the specific list of data, here is my code:</p>

<pre><code>@Override
public RecordAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
    final Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);

    View contactView = inflater.inflate(R.layout.item_record, parent, false);

    RecordAdapter.ViewHolder vh = new ViewHolder(contactView, new RecordAdapter.ViewHolder.IMyViewHolderClicks()
    {
        public void onDelete(final ImageView callerImage)
        {
            new AlertDialog.Builder(context)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle("Delete Record")
                    .setMessage("Are you sure you want to delete this record (Uuid" + callerImage.getTag() + ")?")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                    {
                        @Override
                        public void onClick(DialogInterface dialog, int which)
                        {
                            MainActivity.delete(callerImage.getTag().toString());
                        }
                    })
                    .setNegativeButton("No", null)
                    .show();
        }
    });
    return vh;
}
</code></pre>

<p>On user click on the delete icon, system will pop out an confirmation dialog which u can see from the code above. Here the problem, if user confirm to delete the data, I need to access the variable in my <code>Activity</code> class which is <code>MainActivity.class</code> to delete the specific data from the <code>ArrayList</code> named <code>record</code>. How I do this is set the<code>record</code> variable to static and make it able to access from adapter class like this:</p>

<pre><code>static ArrayList&lt;Record&gt; record = new ArrayList&lt;&gt;();
static RecordAdapter adapter;
public static void delete(String tag)
{
    for (int i = 0; i &lt; record.size(); i++)
    {
        if(record.get(i).getUuid().equals(tag))
        {
            record.remove(i);
            adapter.notifyItemRemoved(i);
            break;
        }
    }
}
</code></pre>

<p>It works perfectly, however, it doesn't look like a good practice, is there any better approach?</p>