title: Refresh Activity when click in RecyclerView
body: <p>I have an activity made of 2 main items: a RecyclerView and a ListView. The RecyclerView acts as a filter and selecting/unselecting items in it will affect the contents of the ListView. Everything works well until I tried to implement the onClickListener on the RecyclerView and realised that's not an option. </p>
  
  <p>I have tried going down the route of setting an OnClickListener inside the ViewHolder, but it needs to call a function inside the main activity and refresh it's listView. Any such interaction triggers the following error:</p>
  
  <pre><code>java.lang.NullPointerException
      at android.support.v7.app.AppCompatDelegateImplBase.&lt;init&gt;(AppCompatDelegateImplBase.java:117)
      at android.support.v7.app.AppCompatDelegateImplV9.&lt;init&gt;(AppCompatDelegateImplV9.java:149)
      at android.support.v7.app.AppCompatDelegateImplV11.&lt;init&gt;(AppCompatDelegateImplV11.java:29)
      at android.support.v7.app.AppCompatDelegateImplV14.&lt;init&gt;(AppCompatDelegateImplV14.java:54)
      at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202)
      at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
      at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
      at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
      at .newsScreen._$_findCachedViewById(newsScreen.kt)
      at .newsScreen.filterNews(newsScreen.kt:71)
      at Cells.NewsFeedList$NewsSource$1.onClick(News Lists.kt:84)
  </code></pre>
  
  <p>Suppose it makes sense since I am trying to access UI from outside it's class, but I could not find alternatives to it. </p>
  
  <p><strong>RecyclerView Adapter:</strong></p>
  
  <pre><code>class NewsFeedList() : RecyclerView.Adapter&lt;NewsFeedList.NewsSource&gt;() {
      private var source: List&lt;NewsFeed&gt; = ArrayList()
  
      constructor(s: ArrayList&lt;NewsFeed&gt;) : this() {
          source = s
      }
  
      class NewsSource : RecyclerView.ViewHolder {
  
          private var mTextView: TextView? = null
  
          constructor(v: View): super(v) {
              mTextView = v.title
          }
  
          fun bindInfo(news: NewsFeed, view: View, int: Int) {
              mTextView!!.text = news.title
              view.tag = int
              view.setOnClickListener { newsScreen().filterNews(view.tag.toString().toInt()) }
              if (news.selected) view.background = ColorDrawable(Color.parseColor(news.color))
              else view.background = ColorDrawable(Color.parseColor(design.backgroundColor))
          }
      }
  
      override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): NewsFeedList.NewsSource {
          val view = LayoutInflater.from(parent!!.context).inflate(R.layout.newsfeed_list, parent, false)
          return NewsSource(view)
      }
  
      override fun onBindViewHolder(holder: NewsFeedList.NewsSource, position: Int) {
          holder.bindInfo(source[position], holder.itemView, position)
      }
  
      override fun getItemCount(): Int {
          return source.count()
      }
  
  }
  </code></pre>
  
  <p>Then, inside my newsScreen class I need to access the RecyclerView adapter with new data </p>
  
  <pre><code>fun filterNews(i: Int) {
  
      newsFeed[i].selected = !newsFeed[i].selected
      filter.adapter = NewsFeedList(newsFeed)
  
  }
  </code></pre>
  
  <p>If I remove any references to filter (RecyclerView), everything is fine, but the purpose of the onClickListener is to refresh the Activities content.</p>
  
  <p>Is there any way to achieve this or should I change the RecyclerView to a different UI element?</p>
  
  <p><strong>Edit:</strong>
  I have tried adding an OnClickListener to the RecyclerView but it does not seem to get triggered. <strong>Code:</strong></p>
  
  <pre><code>filter.adapter = NewsFeedList(newsFeed)
  filter.layoutManager = LinearLayoutManager(this@newsScreen, LinearLayoutManager.HORIZONTAL, false)
  filter.setOnClickListener { v: View? -&gt;
         filterNews(v!!.tag.toString().toInt())
  }
  </code></pre>