title: How to return data from adapter to activity
body: <p>I have an activity that contains a RecyclerView and I show some data that comes from server to it. The problem is that I I have set the onCLick of RecyclerView in <code>MYAdapter</code> class but now I need to handle the OnClick of RecyclerView in based on some data which is my Activity which contains RecyclerView. </p>
  
  <pre><code>public class ActivityAllUsers extends AppCompatActivity {
  
  private RecyclerView recyclerView;
  private RecyclerView.Adapter adapter;
  private List&lt;ListItem&gt; listitems;
  
  private static final String URL_DATA = "http://shayea.tk/sof/get_allusers.php";
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      int id = getIntent().getIntExtra("IDUSERTYPE", 0);// -1 is default value
  
      recyclerView = (RecyclerView) findViewById(R.id.recyvlerview);
      recyclerView.setHasFixedSize(true);
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
  
      listitems = new ArrayList&lt;&gt;();
  
      loadRecyclerviewData();
  }
  
  private void loadRecyclerviewData()
  {
      final ProgressDialog dialog = new ProgressDialog(this);
      dialog.setMessage("Loading...");
      dialog.show();
  
      StringRequest stringRequest = new StringRequest(Request.Method.GET, URL_DATA, new Response.Listener&lt;String&gt;() {
          @Override
          public void onResponse(String s) {
                  dialog.dismiss();
              try {
                  JSONObject jsonObject = new JSONObject(s);
                  JSONArray array = jsonObject.getJSONArray("result");
  
                  for (int i =0;i&lt;array.length();i++)
                  {
                      JSONObject o = array.getJSONObject(i);
                      ListItem item = new ListItem(
                              o.getString("usr_id"),
                              o.getString("usr_name"),
                              o.getString("usr_phone"),
                              o.getString("usr_email"),
                              o.getString("usr_status"),
                              o.getString("prv_name"),
                              o.getString("org_name")
                      );
  
                      listitems.add(item);
                  }
  
                  adapter = new MyAdapter(listitems , getApplicationContext());
                  recyclerView.setAdapter(adapter);
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      }, new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
              dialog.dismiss();
              Toast.makeText(getApplicationContext(),error.getMessage(), Toast.LENGTH_LONG).show();
          }
      });
  
      RequestQueue requestQueue = Volley.newRequestQueue(this);
      requestQueue.add(stringRequest);
  }
  }
  </code></pre>
  
  <p>I want to the OnClick of RecyclerView to be available when ever this <code>int id = getIntent().getIntExtra("IDUSERTYPE", 0);</code> <strong>id</strong> contains <strong>1</strong> and if <strong>id</strong> contains anything else the OnClick shouldn't be active.
  Here is <strong>MyAdapter</strong> class which contains the OnClick of RecyclerView :</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
  
  private List&lt;ListItem&gt; listItems;
  private Context context;
  
  public MyAdapter(List&lt;ListItem&gt; listItems, Context context) {
      this.listItems = listItems;
      this.context = context;
  }
  
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,parent,false);
      return new ViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(ViewHolder holder, final int position) {
  
      final ListItem listItem = listItems.get(position);
  
      holder.txtusername.setText(listItem.getusername());
      holder.txtuseremail.setText(listItem.getEmail());
  
      holder.linearLayout.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              Intent intent = new Intent(context, UserInformation.class);
              intent.putExtra("Details", (Serializable) listItem);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(intent);
  
          }
      });
  }
  
  @Override
  public int getItemCount() {
      return listItems.size();
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder{
  
      public TextView txtusername;
      public TextView txtuseremail;
      public LinearLayout linearLayout;
      public ViewHolder(View itemView) {
          super(itemView);
  
          txtusername = (TextView) itemView.findViewById(R.id.textviewusername);
          txtuseremail = (TextView) itemView.findViewById(R.id.textviewuseremail);
          linearLayout = (LinearLayout) itemView.findViewById(R.id.linearlayout);
      }
  }
  }
  </code></pre>
  
  <p>I need the <strong>id</strong> which is in <strong>ActivityAllUsers</strong> ih here :</p>
  
  <pre><code> holder.linearLayout.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              Intent intent = new Intent(context, UserInformation.class);
              intent.putExtra("Details", (Serializable) listItem);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(intent);
  
          }
      });
  </code></pre>