当前位置:网站首页>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;
}
}
边栏推荐
- [staff] common symbols of staff (Hualian clef | treble clef | bass clef | rest | bar line)
- How to choose between efficiency and correctness of these three implementation methods of distributed locks?
- C语言之数据插入
- Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
- Matplotlib剑客行——容纳百川的艺术家教程
- AMQ 4043 solution for errors when using IBM MQ remote connection
- 一篇详解带你再次重现《统计学习方法》——第二章、感知机模型
- [go practical basis] how to bind and use URL parameters in gin
- Microservice practice | load balancing component and source code analysis
- 告别996,IDEA中必装插件有哪些?
猜你喜欢
Mysql默认事务隔离级别及行锁
我服了,MySQL表500W行,居然有人不做分区?
Chrome browser plug-in fatkun installation and introduction
Mysql 多列IN操作
别找了,Chrome浏览器必装插件都在这了
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
How to use PHP spoole to implement millisecond scheduled tasks
Microservice practice | load balancing component and source code analysis
Enterprise level SaaS CRM implementation
Matplotlib剑客行——容纳百川的艺术家教程
随机推荐
Idea view bytecode configuration
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
Microservice practice | declarative service invocation openfeign practice
FragmentTabHost实现房贷计算器界面
JDBC回顾
[go practical basis] gin efficient artifact, how to bind parameters to structures
Don't look for it. All the necessary plug-ins for Chrome browser are here
自定义Redis连接池
Long summary (code with comments) number structure (C language) -- Chapter 4, string (Part 1)
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
VIM operation command Encyclopedia
idea查看字节码配置
View the port of the application published by was
Mysql 多列IN操作
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
Supplier selection and prequalification of Oracle project management system
微服务实战|手把手教你开发负载均衡组件
西瓜书--第五章.神经网络