title: How to make text in Recyclerview Adapter Header clickable
body: <p>I am still very new to Java, but I'm learning to at least make changes to existing code.</p>
  <p>What I have is an app someone else developed and I am just making small changes to it. I'm trying to set a <code>Textview</code> &quot;Recently Added&quot; so that it can be clicked and changed to &quot;By Date&quot; and back again, then I'll have the API change according to that. If I can get help knowing where to put the <code>onClickListener</code> I think I can get it....</p>
  <p><img src="https://i.stack.imgur.com/W60EN.png" alt="Screenshot" /></p>
  <p>If anyone could help me I would really appreciate it.  Here is the code for the PreachingAdapter.java</p>
  <pre><code>    package com.churchofgod.adapter;
    
      public class PreachingAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;{
  
      public List&lt;LandingData.SermonsData&gt; items;
      public Listpackage&lt;LandingData.PodcastsData&gt; items1;
      public List&lt;LandingData.SingingsData&gt; items2;
      public List&lt;LandingData.SundaySchoolsData&gt; items3;
      Context context;
      int headerType;
  
      private static final int HEADER_VIEW = 1;
  
      public static class PreachingHeaderViewHolder extends RecyclerView.ViewHolder {
          FrameLayout viewApostlesLayout, viewOrdainedMinistersLayout, viewLocationsLayout;
          PreachingHeaderViewHolder(View itemView) {
              super(itemView);
              viewApostlesLayout = itemView.findViewById(R.id.viewApostlesLayout);
              viewOrdainedMinistersLayout = itemView.findViewById(R.id.viewOrdainedMinistersLayout);
              //viewMinistersLayout = (FrameLayout) itemView.findViewById(R.id.viewMinistersLayout);
              viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
          }
      }
  
      public static class SundaySchoolsHeaderViewHolder extends RecyclerView.ViewHolder {
          FrameLayout viewApostlesLayout, viewOrdainedMinistersLayout, viewLocationsLayout;
          SundaySchoolsHeaderViewHolder(View itemView) {
              super(itemView);
              viewApostlesLayout = itemView.findViewById(R.id.viewApostlesLayout);
              viewOrdainedMinistersLayout = itemView.findViewById(R.id.viewOrdainedMinistersLayout);
              //viewMinistersLayout = (FrameLayout) itemView.findViewById(R.id.viewMinistersLayout);
              viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
          }
      }
  
      public static class SingingHeaderViewHolder extends RecyclerView.ViewHolder {
          FrameLayout viewLocationsLayout;
          SingingHeaderViewHolder(View itemView) {
              super(itemView);
              viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
          }
      }
  
      public static class ItemViewHolder extends RecyclerView.ViewHolder {
          CardView cardView;
          ImageView img;
          TextView tvTitle;
          TextView tvDesc;
  
          ItemViewHolder(View itemView) {
              super(itemView);
              cardView = itemView.findViewById(R.id.cardView);
              img = itemView.findViewById(R.id.img);
              tvTitle = itemView.findViewById(R.id.tvTitle);
              tvDesc = itemView.findViewById(R.id.tvDesc);
          }
      }
  
      public PreachingAdapter(List&lt;LandingData.SermonsData&gt; items, Context context, int headerType){
          this.items = items;
          this.context = context;
          this.headerType = headerType;
      }
  
      @Override
      public int getItemCount() {
          if (headerType == 0) {
              return items1.size();
          } else if (headerType == 1 ){
              if (items.size() == 0) {
                  return 1;
              } else {
                  return items.size() + 1;
              }
          }
          else if (headerType == 3)
          {
              return items.size();
          }
          else if (headerType == 4)
          {
              return items3.size();
          }
          else {
              return items2.size() + 1;
          }
      }
  
      @Override
      public int getItemViewType(int position) {
          if (headerType == 0) {
              return super.getItemViewType(position);
          } else if (headerType == 3)
          {
              return items.size();
          } else if (headerType == 4)
          {
              return items3.size();
          }
          else {
              if (position == 0) {
                  return HEADER_VIEW;
              } else {
                  return super.getItemViewType(position);
              }
          }
      }
  
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
          if (viewType == HEADER_VIEW) {
              if (headerType == 1) {
                  View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_all_preaching_header, viewGroup, false);
                  PreachingAdapter.PreachingHeaderViewHolder preachingHeaderViewHolder = new PreachingAdapter.PreachingHeaderViewHolder(view);
                  return preachingHeaderViewHolder;
              }else if (headerType == 4) {
                  View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_all_teaching_header, viewGroup, false);
                  PreachingAdapter.SundaySchoolsHeaderViewHolder sundaySchoolsHeaderViewHolder = new PreachingAdapter.SundaySchoolsHeaderViewHolder(view);
                  return sundaySchoolsHeaderViewHolder;
              } else {
                  View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_all_singing_header, viewGroup, false);
                  PreachingAdapter.SingingHeaderViewHolder singingHeaderViewHolder = new PreachingAdapter.SingingHeaderViewHolder(view);
                  return singingHeaderViewHolder;
              }
          } else {
              Viepackagew view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_preaching, viewGroup, false);
              PreachingAdapter.ItemViewHolder itemViewHolder = new PreachingAdapter.ItemViewHolder(view);
              return itemViewHolder;
          }
      }
  
      @Override
      public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, final int i) {
          try {
              if (viewHolder instanceof ItemViewHolder) {
  
                  PreachingAdapter.ItemViewHolder itemViewHolder = (PreachingAdapter.ItemViewHolder) viewHolder;
                  String imgUrl = &quot;&quot; ,title = &quot;&quot; ,desc = &quot;&quot;;
  
                  if (headerType == 1 || headerType == 3) //||headerType == 4)//sermons
                  {
                      LandingData.SermonsData data = items.get(headerType==3?i:i-1);
                      imgUrl = data.artists.get(0).image;
                      title = data.title;
                      if (data.artists.size() &gt;= 2){
                          String firstMinister = data.artists.get(0).name;
                          String secondMinister = data.artists.get(1).name;
                 packagepackage         desc = firstMinister + &quot; &amp; &quot; + secondMinister;
                      }else{
                          desc = data.artists.get(0).name;
                      }
                      viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              Intent intent = new Intent(context, NowPlayingActivity.class);
                              CurrentPlaying.stopSimpleExoPlayer();
                              intent.putExtra(&quot;data&quot;,items.get(headerType==3?i:i-1));
                              context.startActivity(intent);
                          }
                      });
                  }
                  else if (headerType == 4)
                  {
                      LandingData.SundaySchoolsData data = items3.get(headerType==4?i:i-1);
                      imgUrl = data.artists.get(0).image;
                      title = data.title;
                      if (data.artists.size() &gt;= 2){
                          String firstMinister = data.artists.get(0).name;
                          String secondMinister = data.artists.get(1).name;
                          desc = firstMinister + &quot; &amp; &quot; + secondMinister;
                      }else{
                          desc = data.artists.get(0).name;
                      }
                      viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              Intent intent = new Intent(context, NowPlayingActivity.class);
                              CurrentPlaying.stopSimpleExoPlayer();
                              intent.putExtra(&quot;data&quot;,items3.get(headerType==4?i:i-1));
                              context.startActivity(intent);
                          }
                      });
                  }
                  else if (headerType == 0)//pod casts
                  {
                 package     LandingData.PodcastsData data = items1.get(i);
                      imgUrl = data.image;
                      title = data.title;
                      desc = data.title;
                      viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              Intent intent = new Intent(context, NowPlayingActivity.class);
                              CurrentPlaying.stopSimpleExoPlayer();
                              intent.putExtra(&quot;data&quot;, items1.get(i));
                              context.startActivity(intent);
                          }
                      });
                  }
  
                  else {//singings
                      final LandingData.SingingsData data = items2.get(i - 1);
                      imgUrl = data.image;
                      title = data.title;
                      desc = data.description;
                      viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
  
  
                              Intent intent = new Intent(context, PlaylistActivity.class);
                              intent.putExtra(&quot;data&quot;,data);
                              context.startActivity(intent);
                          }
                      });
                  }
                  Glide.with(context).load(imgUrl).into(itemViewHolder.img);
                  itemViewHolder.tvTitle.setText(title);
                  itemViewHolder.tvDesc.setText(desc);
  
              } else if (viewHolder instanceof PreachingHeaderViewHolder) {
                  PreachingAdapter.PreachingHeaderViewHolder headerViewHolder = (PreachingAdapter.PreachingHeaderViewHolder) viewHolder;
                  headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intent = new Intent(context, LocationsActivity.class);
                          intent.putExtra(&quot;sermon&quot;, true);
                          context.startActivity(intent);
                      }
                  });
  
                  headerViewHolder.viewApostlesLayout.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intent = new Intent(context, MembersActivity.class);
                          intent.putExtra(&quot;TYPE&quot;, &quot;Apostles&quot;);
                          context.startActivity(intent);
                      }
                  });
  
  
                  headerViewHolder.viewOrdainedMinistersLayout.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intent = new Intent(context, MembersActivity.class);
                          intent.putExtra(&quot;TYPE&quot;, &quot;Ordained Ministers&quot;);
                          context.startActivity(intent);
                      }
                  });
  
              } else if (viewHolder instanceof SundaySchoolsHeaderViewHolder) {
                      PreachingAdapter.SundaySchoolsHeaderViewHolder headerViewHolder = (PreachingAdapter.SundaySchoolsHeaderViewHolder) viewHolder;
                      headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Intent intent = new Intent(context, LocationsActivity.class);
                              intent.putExtra(&quot;sermon&quot;,true);
                              context.startActivity(intent);
                          }
                      });
  
                      headerViewHolder.viewApostlesLayout.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Intent intent = new Intent(context, MembersActivity.class);
                              intent.putExtra(&quot;TYPE&quot;,&quot;Apostles&quot;);
                              context.startActivity(intent);
                          }
                      });
  
  
  
                      headerViewHolder.viewOrdainedMinistersLayout.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Intent intent = new Intent(context, MembersActivity.class);
                              intent.putExtra(&quot;TYPE&quot;,&quot;Ordained Ministers&quot;);
                              context.startActivity(intent);
                          }
                      });
  
                  } else if (viewHolder instanceof SingingHeaderViewHolder) {
                  PreachingAdapter.SingingHeaderViewHolder headerViewHolder = (PreachingAdapter.SingingHeaderViewHolder) viewHolder;
                  headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intent = new Intent(context, LocationsActivity.class);
                          intent.putExtra(&quot;sermon&quot;,false);
                          context.startActivity(intent);
                      }
                  });
              }
          } catch (Exception e) {
  
          }
      }
  
      @Override
      public void onAttachedToRecyclerView(RecyclerView recyclerView) {
          super.onAttachedToRecyclerView(recyclerView);
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          public ViewHolder(View itemView) {
              super(itemView);
          }
  
              public void bindView(int position) {
  
             }
      }
  
      }
  </code></pre>
  <p><strong>Here is what I have done in response to the help offered so far</strong></p>
  <pre><code>public static class SundaySchoolsHeaderViewHolder extends RecyclerView.ViewHolder {
          FrameLayout viewApostlesLayout, viewOrdainedMinistersLayout, viewLocationsLayout;
          SundaySchoolsHeaderViewHolder(View itemView) {
              super(itemView);
              viewApostlesLayout = itemView.findViewById(R.id.viewApostlesLayout);
              viewOrdainedMinistersLayout = itemView.findViewById(R.id.viewOrdainedMinistersLayout);
              //viewMinistersLayout = (FrameLayout) itemView.findViewById(R.id.viewMinistersLayout);
              viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
          }
      }
      public static class SortByViewHolder extends RecyclerView.ViewHolder {
          public TextView simpleTextView;
          SortByViewHolder (View itemView) {
              super(itemView);
              simpleTextView= itemView.findViewById(R.id.sort);
          }
      }
  
      public static class SingingHeaderViewHolder extends RecyclerView.ViewHolder {
          FrameLayout viewLocationsLayout;
          SingingHeaderViewHolder(View itemView) {
              super(itemView);
              viewLocationsLayout = itemView.findViewById(R.id.viewLocationsLayout);
          }
      }
  </code></pre>
  <p>and</p>
  <pre><code>                   }
                      });
  
                  } else if (viewHolder instanceof SingingHeaderViewHolder) {
                  PreachingAdapter.SingingHeaderViewHolder headerViewHolder = (PreachingAdapter.SingingHeaderViewHolder) viewHolder;
                  headerViewHolder.viewLocationsLayout.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intent = new Intent(context, LocationsActivity.class);
                          intent.putExtra(&quot;sermon&quot;,false);
                          context.startActivity(intent);
                      }
                  });
              }
  
              if (viewHolder instanceof SortByViewHolder ) {
                  ((SortByViewHolder) viewHolder).simpleTextView.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Intent intent = new Intent(context, LocationsActivity.class);
                          context.startActivity(intent);
  
                      }
                  });
  
              }
          } catch (Exception e) {
  
          }
      }
  
  
  </code></pre>