Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make android buttons switch different XML layouts?
    text
    copied!<p>I just started some android programming recently and I am creating a small project app. I have a few different XML Layout files and want my button to go to that layout. However, when I press the button on the emulator I get this message "Unfortunately "MyApp" Has stopped".</p> <p>Here is my Main Activity Class:</p> <pre><code> import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Shows the Activities screen. Button Button1=(Button)findViewById(R.id.Button1); Button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(MainActivity.this,ActivityList.class); startActivity(i); } }); </code></pre> <p>}</p> <p>This is my XML CODE for the Button:</p> <pre><code> android:id="@+id/Button1" android:layout_width="300dp" android:layout_height="55dp" android:layout_alignLeft="@+id/Menutxt" android:layout_below="@+id/Menutxt" android:layout_marginTop="20dp" android:gravity="center" android:text="@string/Choose_Activity" android:textColor="#ffffffff" android:textSize="25sp" android:typeface="serif" </code></pre> <p>I was wondering if anyone could help me out here, been trying to do this for a few hours and cannot get past it. Thanks. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload