Last active
December 5, 2019 23:30
-
-
Save omidMirrajei/f70757ca7720ffdf18697bf29bc0e07e to your computer and use it in GitHub Desktop.
DinnerDecider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private val foodList = arrayListOf("Pizza", "Chiness", "Hamburger", "McDonalds") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
button_decide.setOnClickListener { | |
val randomFood = Random().nextInt(foodList.count()) | |
textView_selectedFood.text = foodList[randomFood] | |
} | |
button_addFood.setOnClickListener { | |
val newFood = editText_addFood.text.toString() | |
if (newFood.isNotEmpty()) { | |
foodList.add(newFood) | |
Toast.makeText(this, "$newFood added", Toast.LENGTH_SHORT).show() | |
} else Toast.makeText(this, " insert a food", Toast.LENGTH_SHORT).show() | |
editText_addFood.text.clear() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment