i am learning android studio, and i have a question that might be the basic of android studio.
Why doesn't it run from top to bottom like java in eclipse? For example, i have below code:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.game)
var rank2 = mutableListOf(R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4)
val rank1: MutableList<Int> = ArrayList()
var imageView1 = findViewById<ImageView>(R.id.imageView1);
var imageView2 = findViewById<ImageView>(R.id.imageView2);
imageView1.setImageResource(rank2[0])
imageView2.setImageResource(rank2[1])
var x = 0
Log.d("log", "")
imageView1.setOnClickListener{
if (x < 2) {
rank1.add(rank2[2 * x])
if(x<2) {
imageView1.setImageResource(rank2[2 * (x + 1)])
imageView2.setImageResource(rank2[2 * (x + 1) + 1])
x++
}
}
}
imageView2.setOnClickListener{
if (x < 2) {
rank1.add(rank2[2 * x + 1])
if(x<2) {
imageView1.setImageResource(rank2[2 * (x + 1)])
imageView2.setImageResource(rank2[2 * (x + 1) + 1])
x++
}
}
}
Log.d("done", "done")
//do something after finish above code.
}
as soon i run the program, the log "done" shows. what should i do if i want my program to first run the loop, then do another command or function?
Thank you