Android studio button click page jump

(1) First create a page to jump to, that is, a new page, which will jump after clicking.

Steps: app—>src–>main–>res–>layout (right-click)–>New–>Activity–>Empty Activity

After creation, a java file with the same name will be generated.

The initial interface code is as follows, and the interface is shown below for reference only.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Username:"/>
        <EditText
            android:id="@+id/edit1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="____________"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Password:"/>
        <EditText
            android:id="@+id/edit2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="____________"
            android:password="true"/>
    </LinearLayout>
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login"/>
</LinearLayout>

The jump interface code, the same interface is shown later.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@drawable/bg">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:textColor="#DDE0E4"
        android:text="Welcome to the smart agriculture system"
        />
</LinearLayout>

Since there is no change in the page jump, what changes is the main interface. Click the button on the main interface to make the page change, so you only need to write

MainActivity.java file.

Note: Different file names and package names are different. The following is my personal code for reference only.

package com.example.signin;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button btn;
    private EditText edit1;
    private EditText edit2;

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

        initView();
    }

    private void initView() {
        btn = (Button) findViewById(R.id.btn);
        edit1 = (EditText) findViewById(R.id.edit1);
        edit2 = (EditText) findViewById(R.id.edit2);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(edit1.getText().toString().equals("aaa") &&
                   edit2.getText().toString().equals("aaa")){
                    Intent intent = new Intent(MainActivity.this,nextActive.class);
                    startActivity(intent);
                }
                else {
                    Toast.makeText(MainActivity.this,"Incorrect input, please re-enter 
                     Enter ",Toast.LENGTH_LONG).show();
                }
            }
        });
    }

}

The following is the login jump page I completed for reference only.

Initial interface:

After entering the correct username and password, you will jump to the following interface, which is for reference only.

If the input is incorrect, there will be a text prompt:

Related Posts

[Exception]The field file exceeds its maximum permitted size of 1,048,576 bytes.

Java project: Design and implementation of online Heihei network disk system (java+Springboot+ssm+mysql+maven)

Junit unit testing

From shallow to deep, I will take you through the three ways to implement array expansion in Java [recommended collection]

Java connects to the database to implement basic additions, deletions, modifications and queries

[JavaSE] Multi-threading (3) User threads, daemon threads and seven major states of threads

When adding dependencies to pom files, an unknown problem occurs [maven]. A complete solution to dependency error reporting in maven projects.

A simple tutorial on how to use the MybatisX plug-in in SpringBoot (super detailed!!)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*