How to Open a New Activity With a Button in Android Studio [Kotlin 2020]
Вставка
- Опубліковано 15 вер 2024
- In this video, you will learn how to open a new Activity from a Button click. This could be achieved with Intent object and pass it to startActivity method. You will also learn how to navigate back to the previous activity by clicking on the back arrow button in the Action Bar. Therefore, you will learn how to update the title in the actionBar and enable arrow back button by setting setDisplayHomeAsUpEnabled method to true.
🔴 Subscribe for more educational tutorials on CodeWithMazn channel!
Follow me on Instagram
/ codewithmazn
For anyone having an error with the newer version of Android Studio, try this:
val secondActivityBtn: Button = findViewById (R.id.secondActivityBtn)
secondActivityBtn.setOnClickListener() {
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)
}
Thanks for the tutorial Mazn! Keep up the good work!! :)
I already did and it didn't work!
I did the same and it says
Unresolved reference: Button
Unresolved reference: Intent
@@miadudasova5430 same here
sorry to be so off topic but does any of you know a method to get back into an Instagram account??
I was stupid forgot the password. I would love any help you can offer me.
@@mordechaicayson4287 i've the same error than u, i've send like 100 emails and didn't work at all
mine is having error when I am typing the id name to set the click listener. How to fix this?
create a variable first
val name : typeofview = findViewById(R.id.view_id)
name.setOnClickListerner{
}
it should work!
The way you teach is really nice and relaxing , I am designing my first android app with you.
this is what i exactly wanted!! thank you so much!! God bless you!!!
That was really helpful, thank u!
Glad it was helpful!
Finally a video that worked! Thank You
Excelente video, fácil de entender. Saludos desde Venezuela.
Nice one, thank you for the tutorial men.
Well done! Simple,easy to follow
Very clear explained. Thanks!
Can I put 3 Activity in one project?
same question here?
Fast, smart, clean as I wanted :D
Thank you sir .. easier to understand 🤗
Click create activity 2 but when click back create activity 1. But don't close activity 1 so create too much activity. When back close app don't execent. Please check.
Thanks ! (Just increase the volume please)
thank you so much sir, its help me alot...............
Great work God bless you
Quick question. The secondActivityBtn on line 14 of the MainActivity.kt file is red error underlined, saying there is an unresolved reference. Any thoughts on how to fix it? Thanks!
You might missed typed an ID from different layout. Double check on the ID that you are referencing.
same
Same
Hello... how can i remove the action bar? Because I planned to put a new action bar from other resources... thank you...
we apply the tab layout and navigation drawer first and then wanna apply second activity by clicking button. But when we run the app after applying the intent code its not working. So plz can u tell me where we can add the second activity code in java file?
Highly recommend him
Set this up in my code, but it didn't provide the functionality I was looking for. Upon removing the code the back button is still displaying? Anyone have any ideas how to remove it so as not to cause confusion?
Thank you man great job.
I am glad that you liked it. More contents are coming soon! Stay tuned!
Thanks mate!
I have tried this and the program does not see the 'this,' it wants a variable
Thank you so much
welp this didnt work for me it seems
Thank you
thank uu!
¡Muchas gracias!, funciona de maravilla :D
Good
Hi sir, why the Button's ID is not showing out on my MainActivity page even if I typed it correctly?
Double check your main xml file. You might referencing an ID from a different layout file!
val "your button id" = findViewById(R.id."your button id") as Button
after your call your button, then just type button id in your activity and continiu the tutor
i spent a hours to solve this
i am not englishman, cant speak english properly
@@sayyidj6406 english doesnt matter brother you saved me hours thank you
@@arjunvarma9350 well, you might want to learn flutter with android studio, its better workplace, use dart as universal language, which single code can export to android, ios, web even windows app, check its ok bro its worth it (with kotlin or java u need to rewrite your code for ios)
it doesn't work ...
Not working 😢
❤❤❤🧡😀😀✌👌👌👌
val button = findViewById(R.id.button)
button.setOnClickListener{
val intent = Intent(this,SecondActivity::class.java)
startActivity(intent)
}
it gives me error anyway I type it, I don't know what to do. And no one in the entire web gives me an explanation for that. I think maybe if I offer big money to solve this issue someone might help me. I don't really know exactly what solution to take.
Good (don't reply)
why
@@ahmednashaati7397 bcs its bot xD
If possible can you use java instead of kotlin for this. If not how would it be used in java
btnAllTasks.setOnClickListener{
val intent = Intent(packageContext this, show all tasks::class.java)
startActivity(intent)
Yes, you can use Java and I believe its the same for creating Intent! Check my firebase tutorial series! I am using Intent in Java!
to everyone who is strugglin in 1:50 here is the solution, just follow the steps ua-cam.com/video/XwxUovb4Rwk/v-deo.html
Tysm
unresolved reference: secondActivityButton
thank you
i dont get "packageContext" pop up,How to solve this ?
Did you solve this?