Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.view
- import android.content.Intent
- import android.graphics.Color
- import android.os.Bundle
- import android.util.Log
- import android.view.Gravity
- import android.view.View
- import android.view.ViewGroup
- import android.widget.Button
- import android.widget.FrameLayout
- import android.widget.LinearLayout
- import androidx.appcompat.app.AppCompatActivity
- import androidx.constraintlayout.widget.ConstraintLayout
- import kotlinx.android.synthetic.main.activity_level_select.*
- import model.Game
- class LevelSelect : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_level_select)
- val ll_main = findViewById(R.id.ll_main_layout) as LinearLayout
- var n = 0
- for (number in Game.levels) {
- // creating the button
- var button = Button(this)
- // setting layout_width and layout_height using layout parameters
- button.layoutParams = LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT
- )
- n += 1
- button.text = "Level $n"
- button.setOnClickListener {
- Game.currentLevel = button.text.last().toInt()
- val intent = Intent(this, GameActivity::class.java)
- startActivity(intent)
- Log.d("LOL", "Supposed level : " + button.text.last())
- }
- // add Button to LinearLayout
- ll_main.addView(button)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment