Android期末考试即将来袭,我主要把平时的一些小测试的代码放在这里,仅供大家参考!
第一题 加法计算器
实现代码
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class calculator extends AppCompatActivity {
EditText n1,n2,n3;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
n1=findViewById(R.id.n1);
n2=findViewById(R.id.n2);
n3=findViewById(R.id.n3);
btn=findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String x = n1.getText().toString();
String y = n2.getText().toString();
if (!x.equals("")&& !y.equals("")){
int num1 = Integer.parseInt(x);
int num2 = Integer.parseInt(y);
int num3 = num1+num2;
n3.setText(String.valueOf(num3));
Toast.makeText(calculator.this,"计算成功", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(calculator.this,"输入不能为空", Toast.LENGTH_LONG).show();
}
}
});
}
}
<?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"
tools:context=".calculator">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加法计算器"
android:textSize="30sp"
android:layout_gravity="center_horizontal"
android:textColor="#000000"></TextView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#43DCEF">
<EditText
android:id="@+id/n1"
android:textSize="25sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"></EditText>
<TextView
android:layout_width="10dp"
android:layout_height="wrap_content"
android:text="+"></TextView>
<EditText
android:id="@+id/n2"
android:textSize="25sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"></EditText>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:textSize="15sp"></Button>
<EditText
android:id="@+id/n3"
android:textSize="25sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</EditText>
</LinearLayout>
</LinearLayout>
显示结果
第二题 图书信息管理系统
注意:Android Studio安装中文输入法 参考链接:Android studio自带模拟器使用中文拼音输入法
介绍
图书信息管理系统主要分为三个模块,分别是首页、搜索、我的。首页主要展示数据库中图书信息的展示,修改图书信息、删除图书信息;搜索主要实现图书名查询相关信息,添加新的图书;我的主要展示作者的相关信息。
效果图展示
布局实现代码
由于头部和底部的实现都是一样的,我们把它写在单独的文件中,需要的时候引入即可。其中,对应的图片之间粘贴到res目录下的mipmap目录下即可。
头部引入布局文件
<?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="wrap_content"
android:background="#C8C5C5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="图书信息管理"
android:textSize="30sp"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff">
</TextView>
</LinearLayout>
尾部引入布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#09A2E8"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/layout_home"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/img_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/home1"></ImageView>
<TextView
android:id="@+id/tv_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="首页"
android:textColor="#ffffff"
android:textSize="20sp"></TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_search"
android:gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/img_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/search1"></ImageView>
<TextView
android:id="@+id/tv_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索"
android:textColor="#ffffff"
android:textSize="20sp"></TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_my"
android:gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/img_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/my1"></ImageView>
<TextView
android:id="@+id/tv_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我的"
android:textColor="#ffffff"
android:textSize="20sp"></TextView>
</LinearLayout>
</LinearLayout>
帧布局
由于中间的内容是变换的,我们采用帧布局的方式动态显示数据。
整体界面布局
<?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"
tools:context=".book"
android:orientation="vertical">
<include layout="@layout/top"></include>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</FrameLayout>
<include layout="@layout/buttom"></include>
</LinearLayout>
首页帧布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment"
android:id="@+id/home_fragment">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
</FrameLayout>
搜索页面帧布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SearchFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<EditText
android:id="@+id/edt_bname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_marginLeft="10dp"
android:hint="请输入图书名"
android:textColorHint="#D31E1E"
android:textSize="25sp"></EditText>
<Button
android:id="@+id/btn_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:text="查询"
android:textSize="20sp"></Button>
<Button
android:id="@+id/btn_add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:text="添加"
android:textSize="20sp"></Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/search_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</LinearLayout>
</FrameLayout>
我的页面帧布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MyFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/img_person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@mipmap/person"
></ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:textSize="25sp"
android:textStyle="bold"
android:text="姓名:"
></TextView>
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
android:textSize="25sp"
android:textStyle="bold"
android:text="张三"
></TextView>
</LinearLayout>
<SurfaceView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#5A349E"></SurfaceView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:textSize="25sp"
android:textStyle="bold"
android:text="密码:"
></TextView>
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
android:textSize="25sp"
android:textStyle="bold"
android:text="123456"
></TextView>
</LinearLayout>
<SurfaceView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#5C06F6"></SurfaceView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:textSize="25sp"
android:textStyle="bold"
android:text="邮箱:"
></TextView>
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
android:textSize="25sp"
android:textStyle="bold"
android:text="zhangsan@qq.com"
></TextView>
</LinearLayout>
<SurfaceView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#5C06F6"></SurfaceView>
</LinearLayout>
</FrameLayout>
首页数据显示的线性布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_bid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"></TextView>
<TextView
android:id="@+id/tv_bname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"></TextView>
<TextView
android:id="@+id/tv_press"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"></TextView>
<TextView
android:id="@+id/tv_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"></TextView>
</LinearLayout>
添加图书弹出框布局
<?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:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="书名"></TextView>
<EditText
android:id="@+id/add_edt_bname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="ss"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="书的信息"></TextView>
<EditText
android:id="@+id/add_edt_press"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="ss"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="书的价格"></TextView>
<EditText
android:id="@+id/add_edt_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="ss"></EditText>
</LinearLayout>
</LinearLayout>
修改图书弹出框布局
<?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:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="主键"></TextView>
<EditText
android:id="@+id/xiugai_edt_bid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="ss"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="名称"></TextView>
<EditText
android:id="@+id/xiugai_edt_bname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="ss"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="信息"></TextView>
<EditText
android:id="@+id/xiugai_edt_press"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="ss"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="价格"></TextView>
<EditText
android:id="@+id/xiugai_edt_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="ss"></EditText>
</LinearLayout>
</LinearLayout>
操作实现代码
book类
package cn.itcast.book;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class book extends AppCompatActivity implements View.OnClickListener{
LinearLayout layout_home,layout_search,layout_my;
ImageView img_home,img_search,img_my;
TextView tv_home,tv_search,tv_my;
Fragment homeFragment,searchFragment,myFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book);
layout_home=findViewById(R.id.layout_home);
layout_search=findViewById(R.id.layout_search);
layout_my=findViewById(R.id.layout_my);
img_home = findViewById(R.id.img_home);
img_search = findViewById(R.id.img_search);
img_my = findViewById(R.id.img_my);
tv_home = findViewById(R.id.tv_index);
tv_search = findViewById(R.id.tv_search);
tv_my = findViewById(R.id.tv_my);
homeFragment= new HomeFragment();
searchFragment= new SearchFragment();
myFragment= new MyFragment();
layout_home.setOnClickListener(this);
layout_search.setOnClickListener(this);
layout_my.setOnClickListener(this);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
img_home.setImageResource(R.mipmap.home2);
tv_home.setTextColor(Color.BLUE);
transaction.replace(R.id.frame,homeFragment);
transaction.commit();
}
@Override
public void onClick(View view) {
tv_home.setTextColor(Color.WHITE);
img_home.setImageResource(R.mipmap.home1);
tv_search.setTextColor(Color.WHITE);
img_search.setImageResource(R.mipmap.search1);
tv_my.setTextColor(Color.WHITE);
img_my.setImageResource(R.mipmap.my1);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
switch (view.getId()){
case R.id.layout_home:
tv_home.setTextColor(Color.RED);
img_home.setImageResource(R.mipmap.home2);
fragmentTransaction.replace(R.id.frame,homeFragment);
break;
case R.id.layout_search:
tv_search.setTextColor(Color.RED);
img_search.setImageResource(R.mipmap.search2);
fragmentTransaction.replace(R.id.frame,searchFragment);
break;
case R.id.layout_my:
tv_my.setTextColor(Color.RED);
img_my.setImageResource(R.mipmap.my2);
fragmentTransaction.replace(R.id.frame,myFragment);
break;
}
fragmentTransaction.commit();
}
}
HomeFragment
注意
1、我们通过new的方式创建一个空白的fragment类,系统会提供一些方法,我们不用动,直接在onCreateView写我们自己的代码即可。 2、数据库的路径获取自己当前项目的路径,具体步骤为:点击Device File Explorer,找到data下面的data,打开本项目所对应的包名,右键上传数据库文件,点击copy path即可复制路径名,将它粘贴到SQLiteDatabase.openOrCreateDatabase的第一个参数里即可。
package cn.itcast.book;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HomeFragment extends Fragment {
ListView lv;
String[] from={"bid","bname","press","price"};
int[] to={R.id.tv_bid,R.id.tv_bname,R.id.tv_press,R.id.tv_price};
SQLiteDatabase db;
Cursor cursor;
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
public HomeFragment() {
}
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
db=SQLiteDatabase.openOrCreateDatabase("/data/data/cn.itcast.book/bookdb.db",null);
View view = inflater.inflate(R.layout.fragment_home, container, false);
lv =view.findViewById(R.id.lv);
SimpleAdapter adapter = new SimpleAdapter(getContext(),getdata(),R.layout.item,from,to);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TextView tv_bid = view.findViewById(R.id.tv_bid);
TextView tv_bname = view.findViewById(R.id.tv_bname);
TextView tv_press = view.findViewById(R.id.tv_press);
TextView tv_price = view.findViewById(R.id.tv_price);
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
dialog.setTitle("图书修改");
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
View bookview = layoutInflater.inflate(R.layout.book_dialog, null);
final EditText xiugai_edt_bid = bookview.findViewById(R.id.xiugai_edt_bid);
final EditText xiugai_edt_bname = bookview.findViewById(R.id.xiugai_edt_bname);
final EditText xiugai_edt_press = bookview.findViewById(R.id.xiugai_edt_press);
final EditText xiugai_edt_price = bookview.findViewById(R.id.xiugai_edt_price);
cursor.moveToPosition(i);
xiugai_edt_bid.setText(cursor.getInt(0)+"");
xiugai_edt_bname.setText(cursor.getString(1)+"");
xiugai_edt_press.setText(cursor.getString(2)+"");
xiugai_edt_price.setText(cursor.getInt(3)+"");
dialog.setView(bookview);
dialog.setPositiveButton("保存", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ContentValues cv = new ContentValues();
cv.put("bname",xiugai_edt_bname.getText().toString());
cv.put("info",xiugai_edt_press.getText().toString());
cv.put("price",xiugai_edt_price.getText().toString());
int n = db.update("book", cv, "bid=?", new String[]{xiugai_edt_bid.getText().toString()});
if (n>0){
SimpleAdapter simpleAdapter = new SimpleAdapter(getContext(),getdata(),R.layout.item,from,to);
lv.setAdapter(simpleAdapter);
Toast.makeText(getContext(),"图书修改成功",Toast.LENGTH_LONG).show();
}
}
});
dialog.setNegativeButton("取消", null);
dialog.setNegativeButton("删除", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int n = db.delete("book","bid=?", new String[]{xiugai_edt_bid.getText().toString()});
if (n>0){
SimpleAdapter simpleAdapter = new SimpleAdapter(getContext(),getdata(),R.layout.item,from,to);
lv.setAdapter(simpleAdapter);
Toast.makeText(getContext(),"图书删除成功",Toast.LENGTH_LONG).show();
}
}
});
dialog.show();
}
});
return view ;
}
public List<Map<String,Object>> getdata(){
List<Map<String,Object>> list = new ArrayList<>();
cursor = db.query("book", null, null, null, null, null, null, null);
while (cursor.moveToNext()){
HashMap<String, Object> map = new HashMap<>();
int bid = cursor.getInt(0);
String bname = cursor.getString(1);
String press = cursor.getString(2);
int price = cursor.getInt(3);
map.put("bid",bid);
map.put("bname",bname);
map.put("press",press);
map.put("price",price);
list.add(map);
}
return list;
}
}
MyFragment
package cn.itcast.book;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MyFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
public MyFragment() {
}
public static MyFragment newInstance(String param1, String param2) {
MyFragment fragment = new MyFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_my, container, false);
}
}
SearchFragment
package cn.itcast.book;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SearchFragment extends Fragment {
EditText edt_bname;
Button btn_search,btn_add;
ListView search_lv;
String[] from={"bid","bname","press","price"};
SQLiteDatabase db;
Cursor cursor;
int[] to={R.id.tv_bid,R.id.tv_bname,R.id.tv_press,R.id.tv_price};
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
public SearchFragment() {
}
public static SearchFragment newInstance(String param1, String param2) {
SearchFragment fragment = new SearchFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_search, null);
search_lv =view.findViewById(R.id.search_lv);
db=SQLiteDatabase.openOrCreateDatabase("/data/data/cn.itcast.book/bookdb.db",null);
edt_bname = view.findViewById(R.id.edt_bname);
btn_search=view.findViewById(R.id.btn_search);
btn_add=view.findViewById(R.id.btn_add);
btn_search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String bname = edt_bname.getText().toString();
SimpleAdapter adapter = new SimpleAdapter(getContext(),getByBookName(bname),R.layout.item,from,to);
search_lv.setAdapter(adapter);
}
});
btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
dialog.setTitle("添加图书");
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
View add_view = layoutInflater.inflate(R.layout.add_book_dialog, null);
final EditText edt_bname = add_view.findViewById(R.id.add_edt_bname);
final EditText edt_press = add_view.findViewById(R.id.add_edt_press);
final EditText edt_price = add_view.findViewById(R.id.add_edt_price);
dialog.setView(add_view);
dialog.setPositiveButton("添加", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ContentValues cv = new ContentValues();
cv.put("bname",edt_bname.getText().toString());
cv.put("info",edt_press.getText().toString());
cv.put("price",edt_price.getText().toString());
long n = db.insert("book", null, cv);
if (n>0){
Toast.makeText(getContext(),"图书添加成功",Toast.LENGTH_LONG).show();
}
}
});
dialog.setNegativeButton("取消", null);
dialog.show();
}
});
return view;
}
public List<Map<String,Object>> getByBookName(String bookName){
List<Map<String,Object>> list = new ArrayList<>();
cursor = db.query("book", null, "bname=?", new String[]{bookName}, null, null, null, null);
while (cursor.moveToNext()){
HashMap<String, Object> map = new HashMap<>();
int bid = cursor.getInt(0);
String bname = cursor.getString(1);
String press = cursor.getString(2);
int price = cursor.getInt(3);
map.put("bid",bid);
map.put("bname",bname);
map.put("press",press);
map.put("price",price);
list.add(map);
}
return list;
}
}
第三题 实现如图所示界面
MainActivity 类
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="@mipmap/bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="动态"
android:textSize="25sp"
android:background="#000000"
android:textColor="#ffffff"></Button>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="通讯录"
android:textSize="20dp"
android:background="#000000"
android:textColor="#ffffff"></Button>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="搜索"
android:textSize="25sp"
android:background="#000000"
android:textColor="#ffffff"></Button>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="我的"
android:textSize="25sp"
android:background="#000000"
android:textColor="#ffffff"></Button>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/c"
android:layout_alignLeft="@+id/imga"
android:layout_above="@+id/imgb"></ImageView>
<ImageView
android:id="@+id/imgb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/b"
android:layout_alignLeft="@+id/imga"
android:layout_above="@+id/imga"></ImageView>
<ImageView
android:id="@+id/imga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/a"
android:layout_centerInParent="true"></ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/d"
android:layout_alignTop="@+id/imga"
android:layout_alignLeft="@+id/imga"></ImageView>
</RelativeLayout>
第四题 登录
效果展示
布局文件
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#666666"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户登录"
android:textSize="30sp"
android:layout_gravity="center_horizontal"
android:textColor="#000000"></TextView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名"
android:textSize="25sp"></TextView>
<EditText
android:id="@+id/username"
android:layout_marginRight="20dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码"
android:textSize="25sp"></TextView>
<EditText
android:id="@+id/password"
android:layout_marginRight="20dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:inputType="textPassword"></EditText>
</LinearLayout>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="登录"></Button>
</LinearLayout>
实现类
package cn.itcast.test_01;
import androidx.appcompat.app.AppCompatActivity;
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 {
EditText username,password;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = findViewById(R.id.username);
password = findViewById(R.id.password);
btn= findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String user = username.getText().toString();
String pwd = password.getText().toString();
if (user.equals("zhangsan")&&pwd.equals("123123")){
Toast.makeText(MainActivity.this,"恭喜你,登录成功!",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this,"对不起,用户名或密码错误!",Toast.LENGTH_LONG).show();
}
}
});
}
}
第五题 计算标准体重
结果展示
实现代码
界面
activity_main
<?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"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="男女身高标准体重计算"
android:textSize="25sp"
android:textColor="@color/white"
android:paddingTop="10dp"
android:background="@color/purple_700"
></TextView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你的身高"
android:textSize="20sp"
></TextView>
<EditText
android:id="@+id/height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你的性别"
android:textSize="20sp"
android:paddingTop="10dp"
></TextView>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:layout_marginRight="20dp"
android:checked="true"></RadioButton>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"></RadioButton>
</RadioGroup>
</LinearLayout>
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="计算标准体重"
android:layout_gravity="center_horizontal"></Button>
</LinearLayout>
result.xml
<?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"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="35sp"
android:textStyle="bold"
android:textColor="#52DDEF"
></TextView>
<TextView
android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#FF00BCD4"
></TextView>
</LinearLayout>
实现功能
MainActivity
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.RadioButton;
public class MainActivity extends AppCompatActivity {
private RadioButton male;
private EditText editText;
private Button btnSubmit;
String sex="";
private int height;
private float standardWeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSubmit=this.findViewById(R.id.btnSubmit);
editText=this.findViewById(R.id.height);
male= this.findViewById(R.id.male);
if(male.isChecked()){
sex="男";
}else{sex="女";}
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
height=Integer.parseInt(editText.getText().toString());
if(sex.equals("男")){
standardWeight=(float) ((height-80)*0.7);
System.out.println("standardWeight:"+standardWeight);
}else{
standardWeight=(float)((height-70)*0.6);
System.out.println("standardWeight:"+standardWeight);
}
Intent intent=new Intent(MainActivity.this,ResultActivity.class);
intent.putExtra("height",height);
intent.putExtra("weight",standardWeight);
MainActivity.this.startActivity(intent);
}
});
}
}
ResultActivity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ResultActivity extends Activity {
private TextView tv1,tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.result);
tv1=(TextView) this.findViewById(R.id.tv1);
tv2=(TextView) this.findViewById(R.id.tv2);
Intent intent=this.getIntent();
int h=intent.getIntExtra("height",0);
float w=intent.getFloatExtra("weight",0);
String str1="身高为"+h+"cm的男性标准体重计算结果";
String str2="身高为"+h+"cm的男性标准体重计算结果"+w+"kg,本计算结果是根据世界卫生组织计算方法计算得出,仅供参考。";
tv1.setText(str1);
tv2.setText(str2);
}
}
第六题 问卷调查
效果展示
代码实现
界面代码
activity_main
<?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="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="大学生生活消费调查问卷"
android:gravity="center"
android:textColor="@color/white"
android:background="@color/teal_200"></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1、您的性别是:"></TextView>
<RadioGroup
android:id="@+id/sexGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/teal_200">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:checked="true"></RadioButton>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"></RadioButton>
</RadioGroup>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2、您的年级是:"></TextView>
<RadioGroup
android:id="@+id/gradeGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/teal_200">
<RadioButton
android:id="@+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大一"></RadioButton>
<RadioButton
android:id="@+id/second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大二"></RadioButton>
<RadioButton
android:id="@+id/third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大三"></RadioButton>
<RadioButton
android:id="@+id/forth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大四"></RadioButton>
</RadioGroup>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3、您的每月生活费是:"></TextView>
<RadioGroup
android:id="@+id/moneyGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/teal_200">
<RadioButton
android:id="@+id/money_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0-1000"></RadioButton>
<RadioButton
android:id="@+id/money_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1000-1500"></RadioButton>
<RadioButton
android:id="@+id/money_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1500-2000"></RadioButton>
<RadioButton
android:id="@+id/money_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2000以上"></RadioButton>
</RadioGroup>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="4、您的生活费主要花费在哪些方面:"></TextView>
<CheckBox
android:id="@+id/food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="伙食"/>
<CheckBox
android:id="@+id/clothes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="买衣服"/>
<CheckBox
android:id="@+id/travel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="旅游"/>
<CheckBox
android:id="@+id/money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发红包"/>
<CheckBox
android:id="@+id/traffic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="交通"/>
<CheckBox
android:id="@+id/study"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="学习用品"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<Button
android:id="@+id/submitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交"
android:textColor="@color/white"
android:background="#FF1C887E"
android:layout_marginLeft="60dp"
android:layout_marginRight="40dp"></Button>
<Button
android:id="@+id/exitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="退出"
android:textColor="@color/white"
android:background="#FF1C887E"
android:layout_marginRight="50dp"></Button>
</LinearLayout>
</LinearLayout>
result
<?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="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="您提交的信息如下"
android:textSize="30dp"
android:textColor="@color/black"></TextView>
<TextView
android:id="@+id/tvInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="@color/white"
android:background="@color/teal_200"></TextView>
</LinearLayout>
</LinearLayout>
功能代码
MainActivity
package cn.itcast.investigation;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class MainActivity extends AppCompatActivity {
private RadioGroup sexGroup,gradeGroup,moneyGroup;
private RadioButton radioButton,male,female,first,second,third,forth;
private Button submitBtn,exitBtn;
private int checkId[]=new int[]{R.id.food,R.id.clothes,R.id.travel,R.id.money,R.id.traffic,R.id.study};
private String sex,grade,money,content="";
private String info;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sexGroup=findViewById(R.id.sexGroup);
gradeGroup=findViewById(R.id.gradeGroup);
moneyGroup=findViewById(R.id.moneyGroup);
male=findViewById(R.id.male);
female=findViewById(R.id.female);
first=findViewById(R.id.first);
second=findViewById(R.id.second);
third=findViewById(R.id.third);
forth=findViewById(R.id.forth);
exitBtn=findViewById(R.id.exitBtn);
submitBtn=findViewById(R.id.submitBtn);
submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
radioButton = MainActivity.this.findViewById(sexGroup.getCheckedRadioButtonId());
sex= radioButton.getText().toString();
radioButton = MainActivity.this.findViewById(gradeGroup.getCheckedRadioButtonId());
grade= radioButton.getText().toString();
radioButton = MainActivity.this.findViewById(moneyGroup.getCheckedRadioButtonId());
money= radioButton.getText().toString();
CheckBox cb;
for(int i=0;i<checkId.length;i++){
cb=MainActivity.this.findViewById(checkId[i]);
if(cb.isChecked()){
content=content+cb.getText()+"、";
}
}
info="性别:"+sex+"\n"+"年级:"+grade+"\n"+"月生活费:"+money+"\n"+"花费的主要内容:"+content;
System.out.println("信息如下:"+info);
Intent intent=new Intent(MainActivity.this,Result.class);
intent.putExtra("information",info);
MainActivity.this.startActivity(intent);
}
});
exitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MainActivity.this.finish();
}
});
}
}
Result
package cn.itcast.investigation;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class Result extends Activity {
private TextView tvInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
tvInfo=this.findViewById(R.id.tvInfo);
Intent intent=this.getIntent();
String info=intent.getStringExtra("information");
System.out.println("显示信息如下:"+info);
tvInfo.setText(info);
}
}
希望对大家有所帮助!
|