title: Kotlin Android - Refresh ListView from Fragment when an item is added by Main Activity
body: <p>I have a <code>BottomNavigationView</code> with 2 sub menu, Home and Email, and a fab to add items to Email.</p>
  
  <p>I'm using the <code>fragment</code> <code>EmailFragment</code> to handle sub menu click. Now, in EmailFragment I have a ListView. The fab in <code>BottomNavigationMenu</code> is able to add items to <code>EmailFragment</code> <code>ListView</code> from <code>MainActivity</code> and it works fine. The problem is, I see new ListView items only when I reopen <code>EmailFragment</code> with its layout.</p>
  
  <p>I want that when I add items to this ListView appear without reopening fragment.</p>
  
  <p>This is how I add items in MainActivity:</p>
  
  <pre><code> positiveButton.setOnClickListener{
  
                  if(dialogView.email_textInput.text!!.isEmpty() || dialogView.email_password_textInput.text!!.isEmpty()) {
                      Toast.makeText(this, resources.getString(R.string.empty_fields), Toast.LENGTH_LONG).show()
                  }
  
                  else{
  
                      emailAddresses.add(dialogView.email_textInput.text!!.toString())
  
  
                      adapter.notifyDataSetChanged()
  
                      saveData()
  
                  }
              }
  </code></pre>
  
  <p>This is how I save data from MainActivity:</p>
  
  <pre><code>private fun saveData() {
      val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
      val editor = sharedPreferences.edit()
      val gson = Gson()
      val json = gson.toJson(emailAddresses) //convert ArrayList to JSON (shared preferences can't handle ArrayList)
      editor.putString("emailAddresses", json) //save the new JSON with values
      editor.apply() //apply new changes
  }
  </code></pre>
  
  <p>This is how I get data from EmailFragment:</p>
  
  <pre><code>private fun loadData() {
      val sharedPreferences = this.activity!!.getSharedPreferences("shared preferences", MODE_PRIVATE)
      val gson = Gson()
      val json = sharedPreferences.getString("emailAddresses", null)
      val type = object : TypeToken&lt;ArrayList&lt;String&gt;&gt;() {
      }.type
  
      when (json) {
          null -&gt; emailAddresses = ArrayList() //if json is null, so empty, values is just an empty ArrayList
          else -&gt; emailAddresses = gson.fromJson(json, type) //got JSON values and convert them back to ArrayList
  
      }
  }
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,
      savedInstanceState: Bundle?
  
  ): View? {
  
      loadData()
  
      val adapter = ArrayAdapter(this.activity!!.applicationContext, R.layout.listview_text, emailAddresses)
      adapter.notifyDataSetChanged()
  
      val mainView = inflater.inflate(R.layout.fragment_email, container, false)
  
      mainView.email_listView.adapter = adapter
  
      return mainView
  }
  </code></pre>