Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I activite a button to switch to another layout upon clicking?
    text
    copied!<p>This seems to be a simple function but I have read and reviewed countless tutorials and tried multiple times to get this to work and I am still unsuccessful.</p> <p>I have the opening xml page titled "main" I have the 2nd xml page titled "menu" I have the 1st java activity titled "ButtontestingActivity.java" I have the 2nd java activity titled "Menu"</p> <p>In ButtontestingActivity.java I have ...</p> <pre><code>package com.package2.Buttontesting; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class ButtontestingActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button Button1 = (Button) findViewById(R.id.sweetness); Button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent("com.package2.Buttontesting.MENU")); } }); } @Override protected void onPause() { super.onPause(); } } </code></pre> <p>in main.xml I have ...</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/splash" android:orientation="vertical" &gt; &lt;Button android:id="@+id/sweetness" android:layout_width="40dp" android:layout_height="78dp" android:layout_marginLeft="52dp" android:layout_marginTop="40dp" android:visibility="visible" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>In the manifest I have ...</p> <pre><code>&lt;application android:icon="@drawable/face" android:label="@string/app_name" &gt; &lt;activity android:label="@string/app_name" android:name=".ButtontestingActivity" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:label="@string/app_name" android:name=".Menu" &gt; &lt;intent-filter &gt; &lt;action android:name="com.package2.Buttontesting.MENU" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p>and I have android:background="@drawable/menu" in my menu.xml</p> <p>when I install the app in my AVD the first layout shows up fine but when I press the button to open the second layout the AVD sends the message</p> <p>"The application Buttontesting (process com.package2.Buttontesting)has stopped unexpectedly. Please try again"</p> <p>and then I'm returned to the app menu.</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