Nalyd1002

code level

Apr 13th, 2021
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.63 KB | None | 0 0
  1. package com.example.view
  2.  
  3. import android.content.Intent
  4. import android.graphics.Color
  5. import android.os.Bundle
  6. import android.util.Log
  7. import android.view.Gravity
  8. import android.view.View
  9. import android.view.ViewGroup
  10. import android.widget.Button
  11. import android.widget.FrameLayout
  12. import android.widget.LinearLayout
  13. import androidx.appcompat.app.AppCompatActivity
  14. import androidx.constraintlayout.widget.ConstraintLayout
  15. import kotlinx.android.synthetic.main.activity_level_select.*
  16. import model.Game
  17.  
  18.  
  19. class LevelSelect : AppCompatActivity() {
  20.     override fun onCreate(savedInstanceState: Bundle?) {
  21.         super.onCreate(savedInstanceState)
  22.         setContentView(R.layout.activity_level_select)
  23.         val ll_main = findViewById(R.id.ll_main_layout) as LinearLayout
  24.         var n = 0
  25.  
  26.         for (number in Game.levels) {
  27.  
  28.             // creating the button
  29.             var button = Button(this)
  30.             // setting layout_width and layout_height using layout parameters
  31.             button.layoutParams = LinearLayout.LayoutParams(
  32.                 LinearLayout.LayoutParams.WRAP_CONTENT,
  33.                 ViewGroup.LayoutParams.WRAP_CONTENT
  34.             )
  35.             n += 1
  36.             button.text = "Level $n"
  37.  
  38.             button.setOnClickListener {
  39.                 Game.currentLevel = button.text.last().toInt()
  40.                 val intent = Intent(this, GameActivity::class.java)
  41.                 startActivity(intent)
  42.                 Log.d("LOL", "Supposed level : " + button.text.last())
  43.  
  44.             }
  45.             // add Button to LinearLayout
  46.             ll_main.addView(button)
  47.  
  48.  
  49.  
  50.         }
  51.  
  52.     }
  53. }
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment