Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to start activity in Android 2.1
    primarykey
    data
    text
    <p>I am a beginner in programming with Java Android. I am currently confused with how to start an activity in Android 2.1. My current project requires a lot of different activities to work together in one program. Let's say I have a button inside the main.xml and assume the function inside ButtonAdroid.class is the one below: </p> <pre><code>public class ButtonAndroid extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Button button = (Button) findViewById(R.id.button_id); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click } }); } } </code></pre> <p>My goal is to make a connection between the ButtonAndroid.class to another class, let's say its name is NextPage.java. Do you guys know what kind of commands do I need to put inside <code>public void onClick(View v)</code> that will enable the current activity to switch to NextPage.java?</p> <hr> <p>After using your answer, apparently there is still an error. I have 2 classes named HelloRelativeLayout and HelloRelativeLayout2.</p> <p>The error says the application has stopped unexpectedly. Does this mean I have to add intent-filter or something inside the XML?</p> <pre><code>public class HelloRelativeLayout extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Button button = (Button) findViewById(R.id.signIn); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click Intent i = new Intent(HelloRelativeLayout.this, HelloRelativeLayout2.class); startActivity(i); } }); } } </code></pre>
    singulars
    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.
    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