trying to convert java code to kotlin in Android studio flamingo

427 Views Asked by At

hope you are in good health would not take much time. I am working on windows 10 x64 i am making a login/logup page with firebase in flamingo 2022.2.1 Patch 2 , but the tutorial im followiing is using java in a section to which I named as Register(have uploaded its picture) if anyone could help me finding a right tutorial or can tell me how can i translate the code in kotlin. what i hv strive is mentioned in the next section thanks very much

image displaying java code image displaying "register section "

i have tried using online converter but can't trust it coz maybe it has some flaws. i have tried finding video tutorial on flamingo but cant find much, maybe i have to search more

1

There are 1 best solutions below

1
Aashis Shrestha On

Converting .java file to kotlin (.kt) file ( I am using Android Studio Flamingo )

  • Goto top bar in Android Studio
  • Click or open java file you want to convert
  • Select Code ->Select Convert java file to kotlin OR click java file and press Ctrl+Alt+Shift+K to convert Here is the screenshot
  • After converting to kotlin file, you will encounter errors while referencing UI component in kotlin.
  • You need to reference views as below

Code Snippet:

class RegisterActivity : AppCompatActivity(){

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

    val email: EditText= findViewById(R.id.editTextEmail)
    val pass: EditText= findViewById(R.id.editTextPass)
    val register: Button= findViewById(R.id.register)

    register.setOnClickListener {  }

    ...
    ...
}