Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Android realize the registration page and carry the data packet to jump?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "Android how to achieve the registration page and carry the data packet jump", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Android how to achieve the registration page and carry the packet jump" bar!

Effect:

Realize

1. Create an Android file

two。 Create a registration interface and check it as the startup page

3. Write code

Launch the interface activity_register11.xml

Register11.java

Import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import androidx.appcompat.app.ActionBar;import androidx.appcompat.app.AppCompatActivity;public class register11 extends AppCompatActivity {private EditText edtName; private EditText edtSex; private EditText edtAge; private EditText edtPhone; private EditText edtEmail; private EditText edtHomepage; private EditText edtRemark; private Button btnRegister; private Button btnCancel @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_register11); / / active bar icon ActionBar actionBar = getSupportActionBar (); actionBar.setDisplayShowHomeEnabled (true); actionBar.setDisplayUseLogoEnabled (true); actionBar.setLogo (R.mipmap.icon); / / get control instance edtName = findViewById (R.id.edtName) EdtSex = findViewById (R.id.edtSex); edtAge = findViewById (R.id.edtAge); edtPhone = findViewById (R.id.edtPhone); edtEmail = findViewById (R.id.edtEmail); edtHomepage = findViewById (R.id.edtHomepage); edtRemark = findViewById (R.id.edtRemark); btnRegister = findViewById (R.id.btnRegister); btnCancel = findViewById (R.id.btnCancel) / / register the listener btnRegister.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View view) {/ / Save user input data String strName=edtName.getText () .toString () .trim ()) to the registration button / / trim () removes the space String strSex=edtSex.getText (). ToString (). Trim (); String strAge=edtAge.getText (). ToString (). Trim (); / / trim () removes the space String strPhone=edtPhone.getText (). ToString (). Trim () / / trim () removes the space String strEmail=edtEmail.getText (). ToString (). Trim (); String strHomepage=edtHomepage.getText (). ToString (). Trim (); / / trim () removes the space String strRemark=edtRemark.getText (). ToString (). Trim () / / use toast to prompt users to register Toast.makeText (register11.this, "registered successfully", Toast.LENGTH_SHORT). Show (); / / LENGTH_SHORT indicates the length of login time / / create display intention Intent intent = new Intent (register11.this, MainActivity.class) / / create packet encapsulation data (encapsulation) Bundle date = new Bundle (); date.putString ("name", strName); date.putString ("sex", strSex); date.putString ("age", strAge); date.putString ("phone", strPhone) Date.putString ("email", strEmail); date.putString ("homepage", strHomepage); date.putString ("remark", strRemark); / / intent.putExtras (date) by intention to carry packets; / / launch target component startActivity (intent) as intended }}); btnCancel.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View view) {/ / close window finish ();}});}}

Activity_main.xml

ActivityMain.java

Import android.content.Intent;import android.os.Bundle;import android.widget.TextView;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity {protected TextView tvMessage; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); / / get the control instance tvMessage = findViewById (R.id.tvMessage) through the resource identifier / / get intention Intent intent = getIntent (); / / determine whether the intention is empty if (intent! = null) {/ / get intention carry packet (encapsulation) Bundle date = intent.getExtras (); String name = date.getString ("name"); String sex = date.getString ("sex") String age = date.getString ("age"); String phone = date.getString ("phone"); String email = date.getString ("email"); String homepage = date.getString ("homepage"); String remark = date.getString ("remark"); / / splicing user information String message = "registered successfully! \ nname: "+ name +"\ nSex: "+ sex +"\ nAge: "+ age +"\ nTel: "+ phone +"\ nemail: "+ email +"\ nHome page: "+ homepage +"\ nNote: "+ remark; / / sets the tag attribute and displays the user information tvMessage.setText (message). } Thank you for your reading. The above is the content of "how to realize the registration page and carry the data packet jump in Android". After the study of this article, I believe you have a deeper understanding of how to implement the registration page and carry the data packet jump in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report