英文:
trying to convert java code to kotlin in Android studio flamingo
问题
希望你身体健康
不会花太多时间。
我正在使用 Windows 10 x64 工作
我正在使用 Flamingo 2022.2.1 补丁 2 制作一个使用 Firebase 的登录/注册页面,但我正在跟随的教程中有一个部分是使用 Java 编写的,我将其命名为“Register”(已上传其图片)。
如果有人可以帮助我找到合适的教程,或者告诉我如何将代码转换为 Kotlin,我已经在下一部分中描述了我的努力。
非常感谢
我已经尝试使用在线转换器,但不能完全信任它,因为可能存在一些问题。
我也尝试过在 Flamingo 上寻找视频教程,但找不到太多,也许我需要继续搜索。
英文:
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
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
得分: 1
Converting .java file to kotlin (.kt) file ( I am using Android Studio Flamingo )
- 转到 Android Studio 的顶部工具栏
- 打开您要转换的 Java 文件
- 选择 Code -> 选择 Convert java file to kotlin 或者点击 Java 文件并按下 Ctrl+Alt+Shift+K 以进行转换
- 将 Java 文件转换为 Kotlin 文件后,您会在 Kotlin 中引用 UI 组件时遇到错误。
- 您需要按以下方式引用视图
代码段:
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 { }
...
...
}
英文:
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
- 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 { }
...
...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论