In this video we will learn, how to open a new Activity from a Button click. For this we will create a new Intent and pass it to the startActivity method.
Example code for this video:
____________________
❗ Subscribe to the channel:
⏯ Watch more tutorials:
⭐ Become a channel member for exclusive tutorials and other perks:
㊙ Help translating the videos:
💚 Support the content:
💬 Join the Discord chat:
🎧 Audiobooks and podcasts for programmers:
👶 How to get started with Android development:
📣 Follow Coding in Flow on social media:
Facebook:
Instagram:
Twitter:
Blog:
Nguồn: https://sam-pointer.com/
Xem thêm bài viết khác: https://sam-pointer.com/cong-nghe/
Xem thêm Bài Viết:
- Chipset B550 – Kẻ thay thế X570 với mức giá MỀM hơn rất nhiều
- Which SSD Is Better – Samsung 860 PRO vs 850 PRO SSD
- Installing Samsung Evo 860 250Gb SSD in G41 Board | Unbox, Review & how to install OS in ssd + HDD
- Samsung 860 EVO Review and Installation
- Lounch Startup Repair Windows 7 #Start Windows Normally #Blue Screen Starting Windows
* * *
I added a link to the code for this video into the description box!
* * *
Thank you so much, this is really simple.
it works on me but somehow it cant stop making click noises.
are you a german speaker?
Very Nice and concise video. Well Done!
I was wondering what code changes would be needed if you had two or buttons on the same page or in a list.
Thanks for taking the time to develop this.
intent intent new intent intent activity intent intent
bro just use some different words someone like me who is new to java wont get it
Sir how to create label and textbox in android studio
Upon clicking I get the generic "Unfortunatley, the app has stoped working" error. My repo is different than yours but I've copied your steps:
https://github.com/Zemogiter/AmaWeatherApp
Any help?
is this java
Thnks so much
Are you German?
For the button.OnClickListener(), the button shows as expected class or package, how do I resolve it?
it crashes
I had a problem, it says "AAPT: error: resource string/action_settings (aka com.example.myapp:string/action_settings) not found."
In particulary it's missing the main.xml:4…. I only had content_main and actvity_main… I didn't have main
what should I do? I didn't use your code, but I needed to make the button open another activity
Please, help me
hii your video is very useful and easy to understand!!
can i ask a question, so im making expert system on android studio, how can i make the button open another activity? so i can open multiple activitu with just one button
are you a german guy ?
Sir your tutorials are the best! Please keep it up you are such a big help!
package com.example.application.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openActivity2();
}
});
}
public void openActivity2() {
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}
}
For more info on intents and how to pass data from one activity to another watch this:-
https://youtu.be/BY5MtRrAMP8
Thx Bro the German accent is nice.
Hi, thanks for the video first up! I'm having a slight problem though. I try to open another activity having google map in it, and it briefly opens for a second, after which it closes and says "App keeps stopping". What should I do? Please help!
how do you make a second button open a second Activity?
In Designe View then button and Textview is not moving in LinearLayout Plz help
I can't edit the activity_main_XML file…even copy & paste also not working inside the file..can u help me pls
are you android god? thank you soo much for the video
Uncaught TypeError: Cannot read property 'update' of undefined
this is the error im facing . the app keeps on crashing as soon as i press the button
Sehr gutes Video danke wieder dafür, doch wieso änderst du in der xml Datei das Layout immer in Relative ?
Ah yes, knowledge, give me some of that.
this guy is just awesome. thank you for your all effort.
Thank you for the video! It helped me a lot👍
how to make online and offline both on android studio project please tell me
how to connect navigation drawer to main activity
the BG called ic_poule1 is an SVG file introduced in Drawable file as XML file
This is my xml_main
<ImageButton
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="344dp"
android:background="@drawable/ic_poule1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
I have used but the button desapears when i click on.
public class MainActivity extends AppCompatActivity {
ImageSwitcher btn2;
int mDefaultColor;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDefaultColor = ContextCompat.getColor(MainActivity.this,R.color.colorAccent);
btn2 = findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@SuppressLint("ResourceType")
@Override
public void onClick(View v) {
openColorPicker();
}
});
}
public void openColorPicker(){
AmbilWarnaDialog colorPicker = new AmbilWarnaDialog(this, mDefaultColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {
@Override
public void onCancel(AmbilWarnaDialog dialog) {
}
@Override
public void onOk(AmbilWarnaDialog dialog, int color) {
mDefaultColor = color;
btn2.setBackgroundResource(R.drawable.ic_poule1);
btn2.setBackgroundColor(color);
//btn2.R.drawable.ic_poule1.setColor(color);
}
});
colorPicker.show();
}
}
can you please help me color the backGround of button witch is an animal by clicking on the button.
Hi, I wonder the changing of background tint, size, margins of the buttons will affect the function of the button? Cuz I followed what you showed it works at first, but after I changed the background tint and margin all that minor changes it turns out buttons did not show in the emulator…i need help…
I cant put the text in the middle
I can't center the buttons. I am thinking it is because Android is an inferior technology from hell
mine says the app keeps stopping. how to solve it?