How to change New Activity In Android using Button

How to change New Activity In Android using Button




When a developing any android app we need to change one activity to second activity by using button event. In this blog, I will show you how can you did this work with Android. In this blog, I will show you how can we change our Activity from IntroActivity1 to IntroActivity2. 

Firstly you need to create UI for a button by using layout intro_activity_1.XML file. After that set id for button group using android:id="@+id/button"

Example:
intro_activity_1.xml
<Button    android:id="@+id/button"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_weight="1"    android:background="@android:color/transparent"    android:text="NEXT" />


Now change your java class of first activity. In this example we change java file of IntroActivity1.java 
Example: 
IntroActivity1.java
//header, import and package data

public class IntroActivity1 extends AppCompatActivity {


    Button next_btn;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.intro_activity_1); 
           next_btn=(Button)findViewById(R.id.button);//button class

           next_btn.setOnClickListener(new View.OnClickListener(){
   
public void onClick(View arg0){
       
//Start new activity class
              
Intent myIntent=new Intent(IntroActivity1.this,IntroActivity2.class);
             startActivity(myIntent);
      }
  });


}


Best Book for Entrepreneur ==> Strategies To Build Successful Web Agency

0 Response to "How to change New Activity In Android using Button"

Post a Comment

Iklan Atas Artikel

Advetisement

Advertisement

Iklan Bawah Artikel