2017-05-05 4 views

Antwort

1

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.snehpandya.myapplication.MainActivity"> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button"/> 

</android.support.constraint.ConstraintLayout> 

MainActivity.java:

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Button mButton = (Button) findViewById(R.id.button1); 
     mButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent mIntent = new Intent(MainActivity.this, NewActivity.class); 
       startActivity(mIntent); 
       finish(); 
      } 
     }); 
    } 
} 
+0

Bitte als Antwort markieren, wenn dies geholfen hat :) –

Verwandte Themen