Android studio+sqlite实现简单的二手交易、失物招领、招生视频和校园通讯录功能

一、页面展示


1.二手交易页面实现效果

                        

2.失物招领页面实现效果

3.招生视频页面实现效果

4.校园通讯录页面实现效果

二、运行环境

1:客户端使用Android stuido进行开发,gradle版本为7.2;
2:sqlite数据库进行数据存储;
3:使用逍遥模拟器或者Androidstuio自带的模拟器进行运行

三、数据库设计

package com.example.mymemotest.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MyDbHelper extends SQLiteOpenHelper {
    public static final Object DATABASE_NAME = "mytest";
    public static final String TABLE_NAME = "tb_phone";
    //定义数据库名和数据库的版本号
    private  static String DBNAME="mytest.db";
    private  static int VERSION=1;
    //构造方法
    public MyDbHelper(Context context, Object databaseName, Object o, int i) {
        super(context, DBNAME, null, VERSION);
    }
    // 创建数据库
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建数据表
        db.execSQL("create table tb_ershou(ershouId Integer primary key,ershouName String (100),ershouPhone String (100),ershouPrice String (50),ershouContent String (200),ershouImgpath String (400),ershouTime String (50))");
        db.execSQL("create table tb_lost(lostId Integer primary key,lostName String (100),lostPhone String (100),lostTime String (100),lostContent String (200),lostImgpath String (400))");
        db.execSQL("create table tb_phone(Id Integer primary key,Name String (100),Phone String (100))");

        // 向tb_ershou表中插入数据
        db.execSQL("insert into tb_ershou(ershouId, ershouName, ershouPhone, ershouPrice, ershouContent, ershouImgpath, ershouTime) values(1, '洗衣机', '12345678910', '666元', '帮忙出一个洗衣机原价1399元,女生寝室自用,没有洗过鞋子!!有意者私聊,可议价!!', 'https://pic.ulecdn.com/pic/user_800160258/product/prd20210716/ea43de9fe3cd995c_p800x800_xl.jpg', '2024-06-10')");
        db.execSQL("insert into tb_ershou(ershouId, ershouName, ershouPhone, ershouPrice, ershouContent, ershouImgpath, ershouTime) values(2, '二手自行车', '12345678910', '400元', '宝马礼品自行车山地自行车二手双碟刹减震公路,有意者私聊!', 'https://iknow-pic.cdn.bcebos.com/8694a4c27d1ed21b99cf20ccac6eddc451da3f90', '2024-06-10')");
        db.execSQL("insert into tb_ershou(ershouId, ershouName, ershouPhone, ershouPrice, ershouContent, ershouImgpath, ershouTime) values(3, '便利贴', '12345678910', '1元', '便利贴全新,1元一个,自提,有意者私聊!', 'https://gw.alicdn.com/imgextra/i4/1673016872/O1CN01aZ7Py720dQMFHf7nh_!!1673016872.jpg_Q75.jpg_.webp', '2024-06-11')");
        db.execSQL("insert into tb_ershou(ershouId, ershouName, ershouPhone, ershouPrice, ershouContent, ershouImgpath, ershouTime) values(4, '听力耳机', '12345678910', '3元', '出英语听力耳机,自提,有意者私聊!', 'https://img2.baidu.com/it/u=1437894698,2758461437&fm=253&fmt=auto&app=138&f=JPEG?w=691&h=500', '2024-06-11')");

        // 向tb_lost表中插入数据
        db.execSQL("insert into tb_lost(lostId, lostName, lostPhone, lostTime, lostContent, lostImgpath) values(1, '丢失黑色包包', '12345678910', '2024-06-08 15:30', '有没有同学在4-504捡到一个黑色包包,看到的话麻烦联系我!有偿,谢谢~', 'https://gw.alicdn.com/imgextra/i2/2206914396224/O1CN01KGmWLY1vqdmnYyxDe_!!2206914396224-0-lubanu-s.jpg_Q75.jpg_.webp')");
        db.execSQL("insert into tb_lost(lostId, lostName, lostPhone, lostTime, lostContent, lostImgpath) values(2, '捡到校园卡', '12345678910', '2024-06-09 10:00', '高铁站捡到个校园卡,外国语学院的,高铁上不能寄存东西,失主可以联系我等我端午返校给你!', 'https://imgsa.baidu.com/forum/w%3D580/sign=b3e1712042ed2e73fce98624b700a16d/86618b504fc2d56200ae4e49ef1190ef77c66c4d.jpg')");
        db.execSQL("insert into tb_lost(lostId, lostName, lostPhone, lostTime, lostContent, lostImgpath) values(3, '捡到一把雨伞', '12345678910', '2024-06-10 12:00', '在学校食堂丢失一把白色雨伞!若看到请及时联系我!谢谢!!', 'https://img10.360buyimg.com/n1/jfs/t24445/280/165613666/352914/86d22a8/5b27a216Nc89ab54a.jpg')");

        // 向tb_phone表中插入数据
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(1,'学生办公室','028-37608888/37600011')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(2,'教务处','028-37600013/37600211')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(3,'学工处','028-37600223')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(4,'招就处','028-37666666')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(5,'宣传部','028-37600259')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(6,'人力资源部','028-37600016')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(7,'后勤保障处','028-37600300')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(8,'国际部','028-37600209')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(9,'规建处','028-37600303')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(10,'采购中心','028-37600333')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(11,'团委','028-37600222/37600228')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(12,'图书馆','028-37603333')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(13,'信息化与实验室管理处','028-37600271/37600281')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(14,'数字经济学院','028-37600262')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(15,'文学与传媒学院','028-37600242')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(16,'外国语学院','028-37600253')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(17,'机械工程学院','028-37600295')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(18,'电气与电子信息工程学院','028-37600283')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(19,'计算机学院','028-37600276')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(20,'土木工程学院','028-37600287')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(21,'白酒学院','028-37600278')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(22,'商学院','028-37600232/37600247')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(23,'媒体艺术学院','028-37600266')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(24,'艺术学院','028-37600239')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(25,'马克思主义学院','028-37600296')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(26,'通识教学部','028-37600298')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(27,'数学教学部','028-37600299')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(28,'体育学院','028-37600297')");
        db.execSQL("insert into tb_phone(Id, Name, Phone) values(29,'工会/督查、督办办公室','028-37600140')");
    }

    //升级数据库
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        if (oldVersion < 2) {
            // 假设从版本1升级到版本2需要新增一个字段
            sqLiteDatabase.execSQL("ALTER TABLE tb_ershou ADD COLUMN newColumn TEXT");
            sqLiteDatabase.execSQL("ALTER TABLE tb_lost ADD COLUMN newColumn TEXT");
            sqLiteDatabase.execSQL("ALTER TABLE tb_phone ADD COLUMN newColumn TEXT");
        }
        // 添加更多针对不同版本升级的处理
    }
}

四、部分代码

1.失物招领LostActivity.java

package com.example.mymemotest;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.mymemotest.adapter.MemoAdapter2;
import com.example.mymemotest.bean.MemoBean2;
import com.example.mymemotest.db.MyDbHelper;

import java.util.ArrayList;
import java.util.List;

public class LostActivity extends AppCompatActivity {
//定义对象
   private Button btn_add;
   private RecyclerView recy_view;
   private MyDbHelper mhelper;
   SQLiteDatabase db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lost);
        //1 绑定控件
        initView();

        //2 对单击添加单击事件
        btnonclicknext();

        //3完善:从数据库获取数据,显示到RecyclerView控件里面
        recyDisplay();

    }


    //1 绑定控件-----------代码
    private void initView() {
        btn_add=findViewById(R.id.button_addlost);
        recy_view=findViewById(R.id.ll_lost_view);
        mhelper=new MyDbHelper(LostActivity.this, MyDbHelper.DATABASE_NAME, null, 1);
        db=mhelper.getWritableDatabase();
    }

    //2 对单击添加单击事件-----代码
    private void btnonclicknext() {
            btn_add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //单击后跳转到一下页
                    Intent intent=new Intent(LostActivity.this,AddLostActivity.class);
                    startActivity(intent);
//                    finish();
                }
            });
    }

    //3完善:从数据库获取数据,显示到RecyclerView控件里面---------------代码
    private void recyDisplay() {
        //3.1准备数据-----------标题、内容、图片、时间(类)
       List<MemoBean2> arr=new ArrayList();
       //从数据库里面取数据了
       Cursor  cursor=db.rawQuery("select * from tb_lost",null);
      while(cursor.moveToNext()){
          String lostId=cursor.getString(cursor.getColumnIndex("lostId"));
          String lostName=cursor.getString(cursor.getColumnIndex("lostName"));
          String lostPhone=cursor.getString(cursor.getColumnIndex("lostPhone"));
          String lostContent=cursor.getString(cursor.getColumnIndex("lostContent"));
          String lostTime=cursor.getString(cursor.getColumnIndex("lostTime"));
          String lostImgpath=cursor.getString(cursor.getColumnIndex("lostImgpath"));
          MemoBean2 memoBean2=new MemoBean2(lostId,lostName,lostPhone,lostContent,lostTime,lostImgpath);
          arr.add(memoBean2);
      }
       cursor.close();


        //3.2 子布局 recy_item

        //3.3 数据------桥(适配器MemoAdapter)----------------子布局
        MemoAdapter2 adapter=new MemoAdapter2(LostActivity.this,arr);
        //3.4 确定显示的方式
        StaggeredGridLayoutManager st=new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL);
        recy_view.setLayoutManager(st);

        //3.5 让数据显示出来
      recy_view.setAdapter(adapter);
    }

    public void back(View view) {
        finish();
    }
}

2.失物招领AddLostActivity.java

package com.example.mymemotest;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.mymemotest.adapter.MemoAdapter2;
import com.example.mymemotest.bean.MemoBean2;
import com.example.mymemotest.db.MyDbHelper;

import java.util.ArrayList;
import java.util.List;

public class LostActivity extends AppCompatActivity {
//定义对象
   private Button btn_add;
   private RecyclerView recy_view;
   private MyDbHelper mhelper;
   SQLiteDatabase db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lost);
        //1 绑定控件
        initView();

        //2 对单击添加单击事件
        btnonclicknext();

        //3完善:从数据库获取数据,显示到RecyclerView控件里面
        recyDisplay();

    }


    //1 绑定控件-----------代码
    private void initView() {
        btn_add=findViewById(R.id.button_addlost);
        recy_view=findViewById(R.id.ll_lost_view);
        mhelper=new MyDbHelper(LostActivity.this, MyDbHelper.DATABASE_NAME, null, 1);
        db=mhelper.getWritableDatabase();
    }

    //2 对单击添加单击事件-----代码
    private void btnonclicknext() {
            btn_add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //单击后跳转到一下页
                    Intent intent=new Intent(LostActivity.this,AddLostActivity.class);
                    startActivity(intent);
//                    finish();
                }
            });
    }

    //3完善:从数据库获取数据,显示到RecyclerView控件里面---------------代码
    private void recyDisplay() {
        //3.1准备数据-----------标题、内容、图片、时间(类)
       List<MemoBean2> arr=new ArrayList();
       //从数据库里面取数据了
       Cursor  cursor=db.rawQuery("select * from tb_lost",null);
      while(cursor.moveToNext()){
          String lostId=cursor.getString(cursor.getColumnIndex("lostId"));
          String lostName=cursor.getString(cursor.getColumnIndex("lostName"));
          String lostPhone=cursor.getString(cursor.getColumnIndex("lostPhone"));
          String lostContent=cursor.getString(cursor.getColumnIndex("lostContent"));
          String lostTime=cursor.getString(cursor.getColumnIndex("lostTime"));
          String lostImgpath=cursor.getString(cursor.getColumnIndex("lostImgpath"));
          MemoBean2 memoBean2=new MemoBean2(lostId,lostName,lostPhone,lostContent,lostTime,lostImgpath);
          arr.add(memoBean2);
      }
       cursor.close();


        //3.2 子布局 recy_item

        //3.3 数据------桥(适配器MemoAdapter)----------------子布局
        MemoAdapter2 adapter=new MemoAdapter2(LostActivity.this,arr);
        //3.4 确定显示的方式
        StaggeredGridLayoutManager st=new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL);
        recy_view.setLayoutManager(st);

        //3.5 让数据显示出来
      recy_view.setAdapter(adapter);
    }

    public void back(View view) {
        finish();
    }
}

3.失物招领MemoAdapter2.java

package com.example.mymemotest.adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.mymemotest.R;
import com.example.mymemotest.bean.MemoBean2;
import com.example.mymemotest.db.MyDbHelper;

import java.util.List;
import java.util.Random;
//1 类文件后面添加泛型
//2 鼠标定位类文件行红色波浪线处,Alt+Enter键:添加未实现的方法
//3 鼠标定位类文件行ViewHolder处,Alt+Enter键:添加内部类
//4 鼠标定位界面最下方内部类ViewHolder处,添加extends  RecyclerView.ViewHolder
//5 鼠标定位界面最下方内部类ViewHolder红色波浪线处,Alt+Enter键:添加构造方法
//6 定义两个对象:上下文环境和数组
//7 定义两个对象下方的空白处:Alt+Insert键,添加适配器的构造方法

public class MemoAdapter2 extends RecyclerView.Adapter<MemoAdapter2.ViewHolder>  {
    private Context mcontext;
    private List<MemoBean2> arr2;
    private MyDbHelper mhelper2;
    private SQLiteDatabase db;

    public MemoAdapter2(Context mcontext, List<MemoBean2> arr) {
        this.mcontext = mcontext;
        this.arr2 = arr;
    }

    //负责加载item布局
    @NonNull
    @Override
    public MemoAdapter2.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        View view= LayoutInflater.from(mcontext).inflate(R.layout.recy_lost_item,parent,false);
        ViewHolder mholder=new ViewHolder(view);
        return mholder;
    }


    //负责加载item的数据
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onBindViewHolder(@NonNull MemoAdapter2.ViewHolder mholder, final int i) {
        final MemoBean2 memoBean=arr2.get(i);
        mholder.item_title.setText(memoBean.getLostName());
        mholder.item_content.setText(memoBean.getLostContent());
        mholder.item_time.setText(memoBean.getLostTime());
        Glide.with(mcontext).load(memoBean.getLostImgpath()).into(mholder.item_img);

        Random random = new Random();
        int singleColor = Color.argb(255, 249, 249, 250); // 例如白色背景
        int borderColor = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)); // 随机颜色边框,可自定义
        int borderSize = 1; // 边框宽度,按需调整

        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setShape(GradientDrawable.RECTANGLE); // 保持形状为矩形
        gradientDrawable.setCornerRadius(5f); // 保持圆角为10dp
        gradientDrawable.setColor(singleColor); // 设置背景颜色
// 添加边框
        gradientDrawable.setStroke(borderSize, borderColor); // 设置边框颜色和宽度

        mholder.item_layout.setBackground(gradientDrawable); // 应用到子项布局

        mholder.item_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 获取当前点击项的联系电话
                String contactPhone = arr2.get(i).getLostPhone(); // 假设getErshouPhone()是获取联系电话的方法,请根据实际情况调整

                // 弹出对话框显示联系电话
                AlertDialog.Builder dialog = new AlertDialog.Builder(mcontext);
                dialog.setTitle("若您发现失物请及时联系我哦!!");
                dialog.setMessage("联系方式  " + contactPhone); // 直接展示联系电话
                dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // 用户点击确定后的操作,这里可以根据需要定义,例如记录点击事件或直接结束对话框
                        dialogInterface.dismiss();
                    }
                });
                dialog.setCancelable(true); // 允许用户点击外部区域关闭对话框
                dialog.create().show();
            }
        });

    }

    //recyView一共有多少个子项
    @Override
    public int getItemCount() {
        return arr2.size();
    }

    public class ViewHolder  extends  RecyclerView.ViewHolder{
        TextView item_title,item_content,item_time;
        ImageView item_img;
        LinearLayout item_layout;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            item_title=itemView.findViewById(R.id.item_lostName);
            item_content=itemView.findViewById(R.id.item_lostContent);
            item_img=itemView.findViewById(R.id.item_lostimage);
            item_time=itemView.findViewById(R.id.item_lostTime);
            item_layout=itemView.findViewById(R.id.item_lost_layout);

        }
    }
}

4.失物招领MemoBean2.java

package com.example.mymemotest.bean;

public class MemoBean2 {
    public String getLostId() {
        return lostId;
    }

    public void setLostId(String lostId) {
        this.lostId = lostId;
    }

    public String getLostName() {
        return lostName;
    }

    public void setLostName(String lostName) {
        this.lostName = lostName;
    }

    public String getLostPhone() {
        return lostPhone;
    }

    public void setLostPhone(String lostPhone) {
        this.lostPhone = lostPhone;
    }

    public String getLostContent() {
        return lostContent;
    }

    public void setLostContent(String lostContent) {
        this.lostContent = lostContent;
    }

    public String getLostTime() {
        return lostTime;
    }

    public void setLostTime(String lostTime) {
        this.lostTime = lostTime;
    }

    public String getLostImgpath() {
        return lostImgpath;
    }

    public void setLostImgpath(String lostImgpath) {
        this.lostImgpath = lostImgpath;
    }

    private String lostId;
    private String lostName;
    private String lostPhone;
    private String lostContent;
    private String lostTime;
    private String lostImgpath;

    public MemoBean2(String lostId, String lostName, String lostPhone, String lostContent, String lostTime, String lostImgpath) {
        this.lostId = lostId;
        this.lostName = lostName;
        this.lostPhone = lostPhone;
        this.lostContent = lostContent;
        this.lostTime = lostTime;
        this.lostImgpath = lostImgpath;
    }

}

5.失物招领activity_lost.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="wrap_content"
    android:orientation="vertical"
    tools:context=".LostActivity">
    <RelativeLayout
        android:id="@+id/rl_title"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="#743481">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:drawableLeft="@drawable/back"
            android:gravity="center_vertical"
            android:onClick="back"
            android:text="返回"
            android:textColor="#FFFFFF"
            android:textSize="22sp" />
        <TextView
            style="Base.Theme.Sample"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="失物列表"
            android:textColor="#FFFFFF"
            android:textSize="22sp" />
    </RelativeLayout>
    <ImageView
        android:id="@+id/ll_iv_image"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="0dp"
        android:scaleType="centerCrop"
        android:src="@drawable/shiwuzhaoling" />
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/ll_lost_view"
        android:layout_width="match_parent"
        android:layout_height="400dp"/>
    <Button
        android:id="@+id/button_addlost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="添加商品信息"
        android:textStyle="bold"
        android:textColor="#FFFFFF"
        android:layout_gravity="right"
        android:background="#743481"
        android:layout_margin="0dp"        />


</LinearLayout>

6.失物招领activity_addlost_info.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=".AddLostActivity">

    <RelativeLayout
        android:id="@+id/rl_title"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="#743481">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:drawableLeft="@drawable/back"
            android:gravity="center_vertical"
            android:onClick="back"
            android:text="返回"
            android:textColor="#FFFFFF"
            android:textSize="22sp" />

        <TextView
            style="Base.Theme.Sample"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="发布失物信息"
            android:textColor="#FFFFFF"
            android:textSize="22sp" />

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/ll_lostName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/rl_title"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="失物名称:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostName"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:maxLines="1"
            android:singleLine="true"
            android:hint="请输入内容" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_lostDetail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ll_ershouType"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="20dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="详情描述:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostContent"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:inputType="textMultiLine"
            android:hint="请输入内容" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_lostType"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ll_foundNmae"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="20dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="联系电话:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostPhone"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:maxLines="1"
            android:singleLine="true"
            android:hint="请输入内容" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_lostTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ll_foundDetail"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="20dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="丢失时间:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostTime"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:maxLines="1"
            android:singleLine="true"
            android:hint="请输入内容" />

    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="上传失物图片:"
        android:textStyle="bold"
        android:textColor="#000000"
        android:textSize="15sp"
        android:gravity="top"
        android:layout_margin="10dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_margin="10dp">

        <Button
            android:id="@+id/ll_button_camera"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="拍照"
            android:textStyle="bold"
            android:textColor="#000000"
            android:textSize="15sp"
            android:layout_margin="10dp" />

        <Button
            android:id="@+id/ll_button_photo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="从相册中选择"
            android:textStyle="bold"
            android:textColor="#000000"
            android:textSize="15sp"
            android:layout_margin="10dp" />
    </LinearLayout>

    <ImageView
        android:id="@+id/ll_imageView_preview"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:src="@drawable/shiwu"
        android:layout_marginBottom="10dp"
        android:layout_gravity="center" />

    <Button
        android:id="@+id/ll_button_save"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="保存"
        android:textStyle="bold"
        android:textColor="#FFFFFF"
        android:textSize="30sp"
        android:background="#743481"
        android:layout_margin="10dp" />
</LinearLayout>

7.失物招领recy_lost_item.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=".AddLostActivity">

    <RelativeLayout
        android:id="@+id/rl_title"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="#743481">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:drawableLeft="@drawable/back"
            android:gravity="center_vertical"
            android:onClick="back"
            android:text="返回"
            android:textColor="#FFFFFF"
            android:textSize="22sp" />

        <TextView
            style="Base.Theme.Sample"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="发布失物信息"
            android:textColor="#FFFFFF"
            android:textSize="22sp" />

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/ll_lostName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/rl_title"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="失物名称:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostName"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:maxLines="1"
            android:singleLine="true"
            android:hint="请输入内容" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_lostDetail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ll_ershouType"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="20dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="详情描述:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostContent"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:inputType="textMultiLine"
            android:hint="请输入内容" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_lostType"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ll_foundNmae"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="20dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="联系电话:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostPhone"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:maxLines="1"
            android:singleLine="true"
            android:hint="请输入内容" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_lostTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ll_foundDetail"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="20dp"
        android:background="#ffffff"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="丢失时间:"
            android:textColor="#000"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_lostTime"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@null"
            android:maxLines="1"
            android:singleLine="true"
            android:hint="请输入内容" />

    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="上传失物图片:"
        android:textStyle="bold"
        android:textColor="#000000"
        android:textSize="15sp"
        android:gravity="top"
        android:layout_margin="10dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_margin="10dp">

        <Button
            android:id="@+id/ll_button_camera"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="拍照"
            android:textStyle="bold"
            android:textColor="#000000"
            android:textSize="15sp"
            android:layout_margin="10dp" />

        <Button
            android:id="@+id/ll_button_photo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="从相册中选择"
            android:textStyle="bold"
            android:textColor="#000000"
            android:textSize="15sp"
            android:layout_margin="10dp" />
    </LinearLayout>

    <ImageView
        android:id="@+id/ll_imageView_preview"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:src="@drawable/shiwu"
        android:layout_marginBottom="10dp"
        android:layout_gravity="center" />

    <Button
        android:id="@+id/ll_button_save"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="保存"
        android:textStyle="bold"
        android:textColor="#FFFFFF"
        android:textSize="30sp"
        android:background="#743481"
        android:layout_margin="10dp" />
</LinearLayout>

8.AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mymemotest">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
<!--    <uses-feature android:name="android.hardware.camera" />-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".AddSecondhandActivity"></activity>
        <activity android:name=".AddLostActivity"></activity>
        <activity android:name=".VideoPlayActivity"></activity>
        <activity android:name=".index"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SecondhandActivity"></activity>
        <activity android:name=".LostActivity"></activity>
        <activity android:name=".VideoActivity"></activity>
        <activity android:name=".PhoneActivity"></activity>
    </application>

</manifest>

9.build.gradle

apply plugin: 'com.android.application'

android {
    compileSdk 33
    buildToolsVersion '33.0.1'
    defaultConfig {
        applicationId "com.example.mymemotest"
        minSdkVersion 15
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation files('libs/SQLiteStudioRemote.jar')
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation 'androidx.recyclerview:recyclerview:1.3.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.blankj:utilcodex:1.28.4'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
//    api 'com.blankj:utilcode:1.23.7'
}

五、点赞收藏评论 

看完觉得有用的话希望你能点赞收藏评论!!!感谢!!!

  • 15
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值