LoginActivity.kt

Membuka MainActivity dari LoginActivity
mail@pastecode.io avatar
unknown
kotlin
3 years ago
833 B
46
Indexable
Never
package com.bi.myapp.ui.login

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import com.bi.myapp.MainActivity
import com.bi.myapp.R

class LoginActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)

        val etUsername = findViewById<EditText>(R.id.edittext_username)

        val btnLogin = findViewById<Button>(R.id.button_login)
        btnLogin.setOnClickListener {
            val mainIntent = Intent(this, MainActivity::class.java)
            mainIntent.putExtra("username", etUsername.text.toString())
            startActivity(mainIntent)
            finish()
        }
    }
}