onClick navigate to new window in Android app

I am just trying to understand the basics. I have a very simple activity_main.xml shown below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button
    android:id="@+id/view_private"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp"
    android:onClick="seePrivateGroups"
    android:text="View Private Circle"/>


<Button
    android:id="@+id/join_private"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/join_global"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp"
    android:onClick="joinPrivate"
    android:text="Join A Private PrayerCircle" />

<Button
    android:id="@+id/join_global"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/view_private"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="24dp"
    android:onClick="joinGlobal"
    android:text="Join the global PrayerCircle" />

<EditText
    android:id="@+id/email"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/view_private"
    android:layout_marginTop="30dp"
    android:ems="10"
    android:hint="Email:"
    android:inputType="textEmailAddress"
    android:textSelectHandleLeft="@+id/email_tag" />

<EditText
    android:id="@+id/password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/email"
    android:layout_below="@+id/email"
    android:ems="10"
    android:inputType="textPassword"
    android:hint="Password:" />

 <Button
     android:id="@+id/sign_up"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignRight="@+id/join_private"
     android:layout_below="@+id/password"
     android:onClick="signUp"
     android:text="Sign Up" />

 <Button
     android:id="@+id/sign_in"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignBaseline="@+id/sign_up"
     android:layout_alignBottom="@+id/sign_up"
     android:layout_alignLeft="@+id/join_global"
     android:onClick="menu"
     android:text="Sign In" />


</RelativeLayout>

Then also I have my MainActivity.java shown below:

//the main activity function
public class MainActivity extends Activity {

    //this function is run when the application process is created
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //initialize the application with the two keys: application ID and client      key
        Parse.initialize(getApplication(), "TAKEN-OUT", "TAKEN-OUT");
        //to track the uses
        ParseAnalytics.trackAppOpened(getIntent());
    }

    protected void onStart(Bundle savedInstanceState) {
        super.onStart();
        setContentView(R.layout.activity_main);
    }

    //some code removed from here.

    @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;
    }
}

I want to navigate to a new page when Sign Up button is clicked. Do I need a new XML file for this or can I keep it in the activity_main.xml? Could you give some guidance on where I put the xml data for the new page? And how do I specify that I want this click to go to a new page

Answers


As you created an Activity an xml like above, you want on a button click sign up activity should open. Well you can achieve this using intents. These are basically used to navigate between activities

so in your button click listener, you do this :-

Intent i = new Intent(MainActivity.this,SignUpActivity.class);
startActivity(i)

Now SignUp Activity is another activity like the above class file. It will have its own xml layout and you can add widgets in it which are requred for a sign up.

Please do read the android developer guide.


Need Your Help

SQL Query to select most popular data from table

sql oracle

I want to select the most popular name from this table which is Peter

dynamic linking:change of the linking path

c++ c unix dll

Normally it happens that when ever the path of the library that has to be linked dynamically is defined in LD_LIBRARY_PATH or it it will be mentioned with -L flag while creating the binary.