title: struggling with Fragment and RecycleView implement OnItemClick
body: <p>I tried to implement OnItemClickListener in Fragment with RecycleView Adapter, but my code seems not to work well, OnItemClickListener keeps turning red when I try to change it to getContext().
  I've tried to find many ways to get it done, but that makes me find another error in my code.
  .
  your help will make my day brighter,</p>
  <pre><code>public class MountainFragment extends Fragment {
  
  private final int LOCATION_SIZE = 10;
  private final int LOCATION_TYPE = 1;
  
  public MountainFragment() {
      // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.word_list_activity, container, false);
  
      String name, imageName, address;
      Drawable image;
      int resourceId, imageId;
  
      final ArrayList&lt;WorldDataModel&gt; mountainArrays = new ArrayList&lt;WorldDataModel&gt;();
      for (int n = 1; n &lt;= LOCATION_SIZE; n++) {
          //get Location Name
          resourceId = getResources().getIdentifier(&quot;location_name_&quot; + LOCATION_TYPE
                  + &quot;_&quot; + n, &quot;string&quot;, getActivity().getPackageName());
          name = getResources().getString(resourceId);
  
          //get address
          resourceId = getResources().getIdentifier(&quot;location_address_&quot; + LOCATION_TYPE
                  + &quot;_&quot; + n, &quot;string&quot;, getActivity().getPackageName());
          address = getResources().getString(resourceId);
  
          //get image thumbnail
          resourceId = getResources().getIdentifier(&quot;location_thumbnail_&quot; + LOCATION_TYPE
                  + &quot;_&quot; + n, &quot;string&quot;, getActivity().getPackageName());
          imageName = getResources().getString(resourceId);
          imageId = getResources().getIdentifier(imageName, &quot;drawable&quot;, getActivity().getPackageName());
          image = getResources().getDrawable(imageId);
  
          //add new data to list
          mountainArrays.add(new WorldDataModel(name, address, image));
      }
  
      // using simple recycle view
      RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.word_list_activity);
      recyclerView.setLayoutManager(new LinearLayoutManager(this.getContext()));
      RecycleViewWorldAdapter adapter = new RecycleViewWorldAdapter(mountainArrays);
      recyclerView.setAdapter(adapter);
  
      //on list item click
      recyclerView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              WorldDataModel worldDataModel = mountainArrays.get(position);
              Intent intent = new Intent(getActivity(), DetailsActivity.class);
              intent.putExtra(&quot;category&quot;, LOCATION_TYPE);
              intent.putExtra(&quot;location&quot;, position + 1);
              getActivity().startActivity(intent);
          }
      });
  
      // Inflate the layout for this fragment
      return rootView;
  }
  </code></pre>
  <p>and here's my adapter class</p>
  <pre><code>package com.example.mytourguideapp;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  
  import org.jetbrains.annotations.NotNull;
  
  import java.util.ArrayList;
  
  public class RecycleViewWorldAdapter extends RecyclerView.Adapter&lt;RecycleViewWorldAdapter.MyViewHolder&gt; {
  
      private ArrayList&lt;WorldDataModel&gt; worldDataModelArrayList;
  
      public class MyViewHolder extends RecyclerView.ViewHolder {
  
          public TextView textViewLocationName, textViewPlacesName;
          public ImageView imageOnCard;
  
          public MyViewHolder(View itemView) {
              super(itemView);
              textViewLocationName = (TextView) itemView.findViewById(R.id.location_name);
              textViewPlacesName = (TextView) itemView.findViewById(R.id.places_name);
              imageOnCard = (ImageView) itemView.findViewById(R.id.image_on_cardview);
  
          }
      }
  
      public RecycleViewWorldAdapter(ArrayList&lt;WorldDataModel&gt; worldDataModelArrayList) {
          this.worldDataModelArrayList = worldDataModelArrayList;
      }
  
      @Override
      public MyViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.list_item_layout, parent, false);
  
          return new MyViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(RecycleViewWorldAdapter.MyViewHolder holder, int position) {
          WorldDataModel worldDataModel = worldDataModelArrayList.get(position);
          holder.textViewPlacesName.setText(worldDataModel.getName());
          holder.textViewLocationName.setText(worldDataModel.getAddress());
          holder.imageOnCard.setImageDrawable(worldDataModel.getImageThumbnail());
  
      }
  
      @Override
      public int getItemCount() {
          return worldDataModelArrayList.size();
      }
  
  }
  </code></pre>