user2622738
user2622738

Reputation: 25

move between screens xml in android in netbeans

I would like to have two xml pages or screens and have one button to be clicked and move to show the other screen (or xml) with its own button, image and text. This in netbeans 7.3.1 and android. Is there any sample for this or simple code?

Upvotes: 0

Views: 455

Answers (1)

Pradeep shyam
Pradeep shyam

Reputation: 1292

You have to create 2 Separate Activity to move between one another. In below i have added a sample code of 2 activity class(Simple one). You need to add two activity in AndroidManifest.xml file.

For Button click need to add OnClickListener class for it. check this How to navigate from one screen to another screen

MainActivity.java

  public class MainActivity extends Activity { 

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);  

            //To delay 3 seconds to move next screen
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                     moveActivity();
                }
            }, 3000);

        }  

        public void moveActivity()
        {
            Intent goToNextActivity = new Intent(getApplicationContext(), SecondActivity.class);
            startActivity(goToNextActivity);
        }

    }

SecondActivity.java

public class SecondActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_second_activity);  //Layout XML File
    }  


}

AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.app.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.app.SecondActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/> 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

Upvotes: 1

Related Questions