当前位置:网站首页>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;
}
}
边栏推荐
- 企业级SaaS CRM实现
- Typeerror: X () got multiple values for argument 'y‘
- Talk about the secret of high performance of message queue -- zero copy technology
- Knife4j 2.X版本文件上传无选择文件控件问题解决
- Chrome视频下载插件–Video Downloader for Chrome
- 十年开发经验的程序员告诉你,你还缺少哪些核心竞争力?
- Chrome浏览器插件-Fatkun安装和介绍
- [go practical basis] how can gin get the request parameters of get and post
- Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
- Idea view bytecode configuration
猜你喜欢

每天睡觉前30分钟阅读_day4_Files

Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer

Flink - use the streaming batch API to count the number of words

Mysql默认事务隔离级别及行锁

Required request body is missing:(跨域问题)

How to use PHP spoole to implement millisecond scheduled tasks

机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案

京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别

Talk about the secret of high performance of message queue -- zero copy technology

盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
随机推荐
Who is better for Beijing software development? How to find someone to develop system software
MySQL事务
zk配置中心---Config Toolkit配置与使用
Flink - use the streaming batch API to count the number of words
Matplotlib剑客行——初相识Matplotlib
ClassFile - Attributes - Code
Troubleshooting and handling of an online problem caused by redis zadd
大学生四六级作文模板(自创版,成功跨过六级)
微服务实战|声明式服务调用OpenFeign实践
Alibaba /热门json解析开源项目 fastjson2
每天睡觉前30分钟阅读_day3_Files
Actual combat of microservices | discovery and invocation of original ecosystem implementation services
Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method
VIM operation command Encyclopedia
C语言之到底是不是太胖了
Attributes of classfile
Supplier selection and prequalification of Oracle project management system
概念到方法,绝了《统计学习方法》——第三章、k近邻法
Oracle delete tablespace and user
长篇总结(代码有注释)数构(C语言)——第四章、串(上)