Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to add onlclick listener android
    primarykey
    data
    text
    <p>Ok so I have multiple buttons on the home page of my android application. </p> <p>I have seem to have got confused along the way as I have coded the app like this. </p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void aboutus (final View view) { setContentView(R.layout.aboutus); System.out.println("about us clicked"); } </code></pre> <p>And I have put the on click in the xml. </p> <p>However I have things that I need to write code for in the "about us" page. </p> <p>In my about us class I have the following </p> <pre><code>public class AboutUs extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.aboutus); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void onBackPressed() { setContentView(R.layout.activity_main); } } </code></pre> <p>Here is the xml code for the button that is being clicked </p> <pre><code>&lt;ImageButton android:id="@+id/ImageButton01" android:layout_width="134dp" android:layout_height="97dp" android:layout_x="16dp" android:layout_y="150dp" android:onClick="aboutus" android:src="@drawable/aboutus" /&gt; </code></pre> <p>Any code I am writing isn't working on that page? I don't know why? can any one help? </p> <p>Thank you. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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