+ 3

how can I go to the next activity with a button in android studio?

I know how create an empty activity I just don't know how to access the new activity and what are the codes?

8th Jun 2020, 2:45 PM
hamid
hamid - avatar
9 odpowiedzi
+ 4
Main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <Button android:text="Click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btn"/> </LinearLayout>
9th Jun 2020, 2:38 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 4
This is second layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Welcome" android:textSize="56sp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="To The" android:textSize="56sp" android:layout_margin="10dp"/> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="SecondActivty" android:textSize="56sp"/> </LinearLayout>
9th Jun 2020, 2:39 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 4
MainActvity.java package com.mycompany.myapp3; import android.app.*; import android.os.*; import android.view.*; import android.widget.*; import android.content.*; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn=findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View p1) { Intent intent=new Intent(MainActivity.this,secondactivity.class); startActivity(intent); } }); } }
9th Jun 2020, 2:40 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 4
secondactvity.java package com.mycompany.myapp3; import android.os.*; import android.app.*; public class secondactivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.secondactvity); } }
9th Jun 2020, 2:40 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 3
hamid this could be pretty picky stuff for beginners. You need a simple Intent, a second layout that mean you have to create another layout and a another class that's hold the layout u creat that means the second class will hold the UI for your new Activity.
9th Jun 2020, 2:38 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 3
And add this to your Manifest.xml <activity android:name=".secondactivity"> </activity>
9th Jun 2020, 2:42 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 3
You can also find this basic things on internet you can search for more.
9th Jun 2020, 2:42 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 3
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ THANK YOU SO MUCH it was enough for me because I searched a bit of it and wasn't this much clear for me. so valuable information thank again 🙏🙏
9th Jun 2020, 2:46 PM
hamid
hamid - avatar
8th Jun 2020, 8:13 PM
hamid
hamid - avatar