title: How to update viewpager with new content using Kotlin?
body: <p>I have an app, it developed in Kotlin.One of my activity contain Tab layout with viewpager(e.g send ad receive).In Send tab contains data like A,B,C. In Receive tab 1,2,3. All the data from database. i want to update my viewpaer/tabview with new data(like D,E,F .. an 4,5,6.....).
  i tries few methods but does not work.</p>
  
  <blockquote>
    <p>Note: I dont want to refresh the tablayout with old data because it works. i need only how to bind new data.when i close the app and open again it will update with new data but it does not work without close app.</p>
  </blockquote>
  
  <pre><code>private fun setupViewPager(viewPager: ViewPager, it: List&lt;TransactionEntity&gt;?, incoming: TransactionAdapterDirection) {
  
              if (incoming.equals(OUTGOING)) {
                  adapter.addFragment(SendingFragment(it!!, appDatabase, OUTGOING, networkDefinitionProvider), "SEND")
                  adapter.notifyDataSetChanged() //KK
              } else if (incoming.equals(INCOMING)) {
                  adapter.addFragment(ReceiveFragment(it!!, appDatabase, INCOMING, networkDefinitionProvider), "RECEIVE")
                  adapter.notifyDataSetChanged() //KK
              }
  
              viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
  
                  override fun onPageScrollStateChanged(state: Int) {
                  }
  
                  override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
  
                  }
                  override fun onPageSelected(position: Int) {
  
  
                  }
  
              })
  
              viewPager.adapter = adapter
      }
  
  
      inner class ViewPagerAdapter(manager: FragmentManager) : FragmentStatePagerAdapter(manager) {
          private val mFragmentList = ArrayList&lt;Fragment&gt;()
          private val mFragmentTitleList = ArrayList&lt;String&gt;()
  
          override fun getItem(position: Int): Fragment {
              return mFragmentList[position]
          }
  
          override fun getCount(): Int {
              return mFragmentList.size
          }
  
          fun addFragment(fragment: Fragment, title: String) {
              mFragmentList.add(fragment)
              mFragmentTitleList.add(title)
          }
  
          override fun getPageTitle(position: Int): CharSequence {
              return mFragmentTitleList[position]
          }
  
          override fun getItemPosition(`object`: Any): Int {
              return PagerAdapter.POSITION_NONE
          }
      }
  </code></pre>
  
  <p>UPDATE :</p>
  
  <pre><code>override fun getItem(position: Int): Fragment {
  
              if(this.count &lt; 3) {
                  mFragmentList.add(ReceiveFragment(mfragmentIT, mfragmentAB, mfragmentINC, mfragmentnetwork))
                  mFragmentList.add(SendingFragment(mfragmentIT, mfragmentAB, mfragmentINC, mfragmentnetwork))
                  for (i in 1..3) {
                      println(i)
                  }
              }
              return mFragmentList.get(i)
          }
  </code></pre>
  
  <p>UPDATE 2:</p>
  
  <pre><code>override fun getItem(position: Int): Fragment {
              if (position == 0) {
                  val tab1 = this.addFragment(com.crypto.wallet.activities.ReceiveFragment(mfragmentIT,mfragmentAB,mfragmentINC,mfragmentnetwork), "RECEIVE")
                  return tab1 as Fragment
              } else {
                  val tab2 = this.addFragment(com.crypto.wallet.activities.SendingFragment(mfragmentIT,mfragmentAB,mfragmentINC,mfragmentnetwork), "SEND")
                  return tab2 as Fragment
              }
          }
  </code></pre>