Advertisement
darryljf

MainActivity.kt

Mar 27th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.11 KB | None | 0 0
  1. private const val LIST_CONTENT = ""
  2.  
  3. class MainActivity : AppCompatActivity() {
  4.     override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
  5.         super.onSaveInstanceState(outState, outPersistentState)
  6.  
  7.         outState.putString(LIST_CONTENT,shoppingList.text.toString())
  8.     }
  9.  
  10.     override fun onRestoreInstanceState(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
  11.         super.onRestoreInstanceState(savedInstanceState, persistentState)
  12.  
  13.         shoppingList.text = savedInstanceState?.getString(LIST_CONTENT,"")
  14.     }
  15.  
  16.     override fun onCreate(savedInstanceState: Bundle?) {
  17.         super.onCreate(savedInstanceState)
  18.         setContentView(R.layout.activity_main)
  19.  
  20.         val shoppingInput: EditText = findViewById(R.id.shoppingInput)
  21.         val addBtn: Button = findViewById(R.id.addBtn)
  22.         val shoppingList: TextView = findViewById(R.id.shoppingList)
  23.  
  24.         addBtn.setOnClickListener {
  25.             shoppingList.append(shoppingInput.text)
  26.             shoppingList.append("\n")
  27.             shoppingInput.setText("")
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement