Trying to Store EditText Values in SharedPrefs using a Single addTextChangedListener The code  is completely functional but I'd rather not call two functions when I know it can be done more efficiently. My goal is to store EditText values in SharedPrefs using a single addTextChangedListener.  Any advice is much appreciated! 

fun preserveText() {


    val sharedPref: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)

    field_1.setText(sharedPref.getString("autoSave", ""))
    field_1.addTextChangedListener(object : TextWatcher {
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {

        }

        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {

        }

        override fun afterTextChanged(s: Editable) {
            sharedPref.edit().putString("autoSave", s.toString()).apply()


        }
    })
}

fun preserveText2() {


    val sharedPref: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)

    field_2.setText(sharedPref.getString("autoSave2", ""))
    field_2.addTextChangedListener(object : TextWatcher {
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {

        }

        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {

        }

        override fun afterTextChanged(s: Editable) {
            sharedPref.edit().putString("autoSave2", s.toString()).apply()


        }
    })
}
I'm not sure if what I write below is what you are looking for.  Also I don't know much about Android, so maybe that would not work for some reason.

preserveText(field1, "autoSave")
preserveText(field2, "autoSave2")

val sharedPref: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)

fun preserveText(field: Type????, itemName: String) {
    field.setText(sharedPref.getString(itemName, ""))
    field.addTextChangedListener(object : TextWatcher {
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { }

        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { }

        override fun afterTextChanged(s: Editable) {
            sharedPref.edit().putString(itemName, s.toString()).apply()
        }
    })
}