title: How to rebind item in RecyclerView when the data changed in Kotlin?
body: <p>I customize a RecyclerView class which will display the content of <code>val backupItemList: List&lt;MSetting&gt;</code> in Kotlin in Code B</p>
  
  <p>Now I modify the data of backupItemList outside  RecyclerView class, I think the Code D  will display the latest data in UI, but I failed, the UI is still to display old data.
  I have to use Code C to display the latest data.</p>
  
  <p>What's wrong with the Code D?</p>
  
  <p><strong>Code A</strong></p>
  
  <pre><code>class UIMain : AppCompatActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.layout_main)                       
  
          allList= SettingHandler().getListAllSetting()            
  
          mRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false)
          mCustomAdapter= CustomAdapter(allList)
          mRecyclerView.adapter= mCustomAdapter
  
  
     }
  
  
     public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
         //Code C          
         if (resultCode == RESULT_OK) {
             allList=SettingHandler().getListAllSetting()
             mCustomAdapter= CustomAdapter(allList)
             mRecyclerView.adapter= mCustomAdapter
             mCustomAdapter.notifyDataSetChanged()
             mCustomAdapter.setSelectedItem(selectedBackupItem)  
         }
  
  
         //Code D     
         if (resultCode == RESULT_OK) {
            allList=SettingHandler().getListAllSetting()                
            mCustomAdapter.setSelectedItem(selectedBackupItem)                
         }         
  
     }        
  
  }
  </code></pre>
  
  <p><strong>Code B</strong></p>
  
  <pre><code>  class CustomAdapter (val backupItemList: List&lt;MSetting&gt;) : RecyclerView.Adapter&lt;CustomAdapter.ViewHolder&gt;() {
  
          val noRecord=-1
          private var mSelectedItem = noRecord
  
          override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomAdapter.ViewHolder {
              val v = LayoutInflater.from(parent.context).inflate(R.layout.item_recyclerview, parent, false)
              return ViewHolder(v)
          }
  
          fun getSelectedItem():Int{
              return  mSelectedItem
          }
  
          fun setSelectedItem(index:Int){
              if (index in 0..(backupItemList.size-1) ){
                  mSelectedItem=index
                  notifyDataSetChanged();
              }
  
          }
  
          override fun onBindViewHolder(holder: CustomAdapter.ViewHolder, position: Int) {
              holder.bindItems(backupItemList[position])
          }
  
          override fun getItemCount(): Int {
              return backupItemList.size
          }
  
          inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  
              fun bindItems(aMSetting: MSetting) {
                  itemView.tvSubject.text=aMSetting.name
                  itemView.tvCreatedDate.text=aMSetting.createdDate.toDateString()
                  itemView.tvDescription.text=aMSetting.description   
                  itemView.radioButton.setOnClickListener {
                  mSelectedItem=adapterPosition
                  notifyDataSetChanged();
              }
  
              if(adapterPosition == 0 &amp;&amp; mSelectedItem == noRecord) {             
                  itemView.radioButton.isChecked = true
                  mSelectedItem=adapterPosition
              }
              else {
                  itemView.radioButton.isChecked =(adapterPosition == mSelectedItem)
              }       
              }
  
          }
  
      }
  </code></pre>
  
  <p><strong>To civic.LiLister:</strong></p>
  
  <p>Both Code C And Code D get the same result if I use Code E (I replace val with var),why?</p>
  
  <p><strong>Code E</strong></p>
  
  <pre><code>  class CustomAdapter (var backupItemList: List&lt;MSetting&gt;) : RecyclerView.Adapter&lt;CustomAdapter.ViewHolder&gt;() {
  
          val noRecord=-1
          private var mSelectedItem = noRecord
  
          override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomAdapter.ViewHolder {
              val v = LayoutInflater.from(parent.context).inflate(R.layout.item_recyclerview, parent, false)
              return ViewHolder(v)
          }
  
          fun getSelectedItem():Int{
              return  mSelectedItem
          }
  
          fun setSelectedItem(index:Int){
              if (index in 0..(backupItemList.size-1) ){
                  mSelectedItem=index
                  notifyDataSetChanged();
              }
  
          }
  
          override fun onBindViewHolder(holder: CustomAdapter.ViewHolder, position: Int) {
              holder.bindItems(backupItemList[position])
          }
  
          override fun getItemCount(): Int {
              return backupItemList.size
          }
  
          inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  
              fun bindItems(aMSetting: MSetting) {
                  itemView.tvSubject.text=aMSetting.name
                  itemView.tvCreatedDate.text=aMSetting.createdDate.toDateString()
                  itemView.tvDescription.text=aMSetting.description   
                  itemView.radioButton.setOnClickListener {
                  mSelectedItem=adapterPosition
                  notifyDataSetChanged();
              }
  
              if(adapterPosition == 0 &amp;&amp; mSelectedItem == noRecord) {             
                  itemView.radioButton.isChecked = true
                  mSelectedItem=adapterPosition
              }
              else {
                  itemView.radioButton.isChecked =(adapterPosition == mSelectedItem)
              }       
              }
  
          }
  
      }
  </code></pre>