当前位置:网站首页>Creation and jump of activity
Creation and jump of activity
2022-07-02 09:33:00 【FF small confused acridine~】
Mission requirements :
All classes need to be submitted Java Source file code and layout file code (xml file ), Be careful : Submit Java Select the code language as Java, When submitting the layout file code, select the code language as XML
Task description :
Achieve the following program effects as required , Figure 1 shows the main interface of the program .
(1) Click in the interface “ Please log in ” Jump to the login screen , Click on the login screen “ One click login of the local number ” Button to return to the main interface of the program , And the mobile phone number entered by the user is returned to the main interface and displayed in the position of the member name , What was just shown “ Please log in ” Change it to “ Logged in ”;
(2) Click... In the main interface “ Frequently used information ” Jump to the common information interface , When jumping, you need to put all the information ( full name 、 cell-phone number 、 mailbox 、 Address , These attributes need to be encapsulated in Information Class , Transfer data by object ) Transfer to this interface for display .
The picture resources required in the program are connected :https://pan.baidu.com/s/1T624eEXyt9kFSfvdGuGdhw Extraction code :p9g9




AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.homework07">
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label=" Journey " android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
<activity android:name=".LoginActivity" android:label=" Sign in "></activity>
<activity android:name=".InformationActivity" android:label=" Frequently used information "></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="20dp">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/photo"/>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/tv_user" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Dear members " android:textColor="@android:color/white" android:textSize="23sp" android:textStyle="bold" android:layout_marginTop="5dp"/>
<TextView android:id="@+id/tv_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:text=" Please log in " android:textColor="@android:color/white" android:textSize="15sp"/>
</LinearLayout>
</LinearLayout>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" My tools " android:textSize="26sp" android:textColor="#737373" android:layout_marginTop="10dp"/>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:padding="15dp">
<LinearLayout android:id="@+id/information" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="10dp">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/info"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Frequently used information " android:textSize="16sp" android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="10dp">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/video"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Live broadcast " android:textSize="16sp" android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="10dp">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/outside"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Travel list " android:textSize="16sp" android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="10dp">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/travel"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Travel footprints " android:textSize="16sp" android:layout_marginTop="10dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
login_layout.xml:
<?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">
<ImageView android:layout_width="120dp" android:layout_height="120dp" android:src="@drawable/photo" android:layout_marginTop="80dp" android:layout_gravity="center_horizontal"/>
<EditText android:id="@+id/phoneNum" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:hint=" Please enter this phone number " android:layout_margin="16dp"/>
<Button android:id="@+id/btn_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:text=" One click login of the local number " android:textColor="@android:color/white" android:background="#FF8800"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:text=" Other ways to log in " android:textColor="#737373" android:background="#FAFAFA" android:layout_marginTop="10dp"/>
</LinearLayout>
info_layout.xml:
<?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">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" full name :" android:textSize="20sp"/>
<EditText android:id="@+id/et_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Phone number :" android:textSize="20sp"/>
<EditText android:id="@+id/et_phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" mailbox :" android:textSize="20sp"/>
<EditText android:id="@+id/et_email" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Address :" android:textSize="20sp"/>
<EditText android:id="@+id/et_address" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
MainActivity.java:
package com.example.homework07;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView loginTextView;
private TextView user;
private final int LOGIN_REQUEST = 99;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout information = findViewById(R.id.information);
loginTextView = findViewById(R.id.tv_login);
user = findViewById(R.id.tv_user);
loginTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Activity Jump
Intent intent = new Intent();
// Set purpose Activity class
intent.setClass(MainActivity.this,LoginActivity.class);
// Jump to the new Activity, Return response
startActivityForResult(intent,LOGIN_REQUEST);
}
});
information.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Activity Jump
Intent intent = new Intent();
// Set purpose Activity class
intent.setClass(MainActivity.this,InformationActivity.class);
// Pass custom type objects
Information info = new Information(" Wang Yibo ","189****1234","[email protected]"," China ");
intent.putExtra("info",info);
// Jump to the new Activity, No response returned
startActivity(intent);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == 100 && requestCode == LOGIN_REQUEST){
String phoneNum = data.getStringExtra("phoneNum");
// Consider that the number of digits of mobile phone number in real life is 11 position
if(!phoneNum.isEmpty() && phoneNum.length()== 11){
user.setText(phoneNum);
loginTextView.setText(" Logged in ");
}
}
}
}
LoginActivity.java:
package com.example.homework07;
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;
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_layout);
final EditText text = findViewById(R.id.phoneNum);
Button loginBtn = findViewById(R.id.btn_login);
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Return the data
Intent response = new Intent();
response.putExtra("phoneNum",text.getText().toString());
// Respond to
setResult(100,response);
// End the current LoginActivity
finish();
}
});
}
}
InformationActivity.java:
package com.example.homework07;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
public class InformationActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info_layout);
// Accept from MainActivity Data transferred
Intent request = getIntent();
// Get custom type data
Information information = (Information) request.getSerializableExtra("info");
String name = information.getName();
String phone = information.getPhone();
String email = information.getEmail();
String address = information.getAddress();
EditText nameET = findViewById(R.id.et_name);
EditText phoneET = findViewById(R.id.et_phone);
EditText emailET = findViewById(R.id.et_email);
EditText addressET = findViewById(R.id.et_address);
nameET.setText(name);
phoneET.setText(phone);
emailET.setText(email);
addressET.setText(address);
}
}
Information.java:
package com.example.homework07;
import java.io.Serializable;
// Use Intent When passing objects of this type , You need to make this class implement Serializable Interface
public class Information implements Serializable {
private String name;
private String phone;
private String email;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Information() {
}
public Information(String name, String phone, String email, String address) {
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
}
}
边栏推荐
- Mathematics in machine learning -- point estimation (I): basic knowledge
- Mysql 多列IN操作
- Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
- 微服务实战|手把手教你开发负载均衡组件
- Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
- 京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
- 盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
- [go practical basis] how can gin get the request parameters of get and post
- [go practical basis] how to bind and use URL parameters in gin
- 告别996,IDEA中必装插件有哪些?
猜你喜欢

Micro service practice | introduction and practice of zuul, a micro service gateway

The channel cannot be viewed when the queue manager is running

Watermelon book -- Chapter 6 Support vector machine (SVM)

Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)

微服务实战|手把手教你开发负载均衡组件

Microservice practice | load balancing component and source code analysis

Matplotlib swordsman - a stylist who can draw without tools and code

Typora安装包分享
![[go practical basis] how can gin get the request parameters of get and post](/img/fd/66074d157d93bcf20a5d3b37da9b3e.png)
[go practical basis] how can gin get the request parameters of get and post

Chrome video download Plug-in – video downloader for Chrome
随机推荐
Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
Customize redis connection pool
JDBC回顾
VIM操作命令大全
Chrome user script manager tempermonkey monkey
C语言之到底是不是太胖了
Chrome video download Plug-in – video downloader for Chrome
Mysql默认事务隔离级别及行锁
Oracle modifies tablespace names and data files
What are the waiting methods of selenium
JVM指令助记符
AMQ 4043 solution for errors when using IBM MQ remote connection
Matplotlib剑客行——容纳百川的艺术家教程
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
idea查看字节码配置
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
Watermelon book -- Chapter 6 Support vector machine (SVM)
Knife4j 2. Solution to the problem of file control without selection when uploading x version files
Microservice practice | teach you to develop load balancing components hand in hand
Who is better for Beijing software development? How to find someone to develop system software