zoukankan      html  css  js  c++  java
  • android课程设计报告

     

     

     

    Android移动应用开发

    课程设计报告

    (2019—2020学年 Ⅰ学期)

    电子词典

                   信息与控制工程           

                  计算机科学与技术          

                       1701                

                      高兴                

    指导教师                                

    目录

    一、需求分析

    1.1引言

    1.1.1编写目的

    1.1.2项目背景

    1.2功能需求分析

    1.2.1功能描述

    1.3系统功能用例图

    1.4系统开发及运行环境

    二、功能设计

    2.1系统详细设计

    2.1.1进入界面

    2.1.2界面

    2.1.3添加界面

    2.1.4删除界面

    2.2数据库

    2.2.1表名

    2.2.2表结构

    2.2.3数据库的创建

         三、关键源代码

    四、实际测试

         五、项目总结

    一、需求分析

    1.1引言

    21世纪以来,科技发展势头迅猛,电子行业更可以说得上是日新月异。从各个方面来看,由于智能手机的普及,手机APP已然成为了电子行业中的领头羊。

    1.1.1编写目的

    词典对于人们学习知识,认识世界有着不可估量的价值,可以说是每一个人开启学习殿堂的第一扇门。但是传统的词典有着体积大,不便于携带的劣势,在如今飞速发展的现代社会,这显然并不会成为大多数人的最佳选择。于是电子词典手机APP就如雨后春笋般层出不穷,成为了词典这个大家族中不可或缺的一员。

    1.1.2项目背景

    比起传统词典,手机电子词典具备了便于携带、操作简单、方便快捷等优点。如今市面上各大应用市场中的电子词典大多占用内存大,对手机的硬件配置要求也比较高,运行起来需要占用的资源较大。所以本项目意在开发出一款占用内存小,适用度较高,便于操作,能被大部分用户所接受的手机APP软件。

    本文详细介绍了开发软件所用到的的数据库的创建过程、开发软件的环境配置过程、以及细致地分析了整个软件的功能性与实用性。

    本项目基于Android平台,使用了SQLite轻量级数据库实现了本地查询,单词本,单词释义等功能,研究方法和技术主要涉及Android操作系统应用层开发,经过反复测试,该项目现已研发完成。

    1.2功能需求分析

    1.2.1功能描述

     1.2.1.1主要功能

    通过开发前期对于各大手机软件应用市场进行市场调研,得到了一份基本功能数据汇总,确定了大部分电子词典软件都包含着的基本功能,也就是用户对于电子词典手机APP的主要需求。在仔细研究以及分析这些数据之后,以下是电子词典这个软件所需要基本的功能:

    (1)检索功能,这个最核心的功能,实现了单词的查询操作。

    (2)添加功能,实现生词的添加。

    (3)删除功能,实现错误输入单词的删除。

    1.3.系统功能用例图

    图1.3系统功能用例图

    1.4系统开发及运行环境

    开发环境:android studio

    运行环境:Android智能手机/模拟器

     

     

    二、功能设计

    2.1系统详细设计

    2.1.1进入界面

                                                                                                                                                            

     

    2.1.1 进入界面

    2.1.2主界面

     

     

    2.1.2主界面

    2.1.3添加界面

     

    2.1.3 添加界面

    2.1.4删除界面

     

    2.1.4删除界面

    2.2数据库

    2.2.1表名tb_dict

    2.2.2表结构

     

    2.2.3数据库的创建

    package com.example;

    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;
    import androidx.annotation.Nullable;

    public class DBOpenHelper extends SQLiteOpenHelper {
        final String CREATE_TABLE_SQL="create table tb_dict(_id integer primary key autoincrement,word,detail)";

        public DBOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
            super(context, name, null, version);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(CREATE_TABLE_SQL);
        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.i("词典","--版本更新"+oldVersion+"-->"+newVersion);
        }
    }

     

     

     

    三、关键源代码

    3.1.1进入界面布局代码

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 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:background="@drawable/bg"
        tools:context=".LoadingActivity">

        <Button
            android:id="@+id/Loading"
            android:layout_width="150dp"
            android:layout_height="79dp"
            android:layout_marginBottom="92dp"
            android:background="@drawable/shape"
            android:text="进入"
            android:textColor="#FFFFFF"
            android:textStyle="bold"
            android:textSize="40dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            tools:ignore="MissingConstraints" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    3.1.2进入界面activity代码

    package com.example;

    import androidx.appcompat.app.AppCompatActivity;

    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;

    public class LoadingActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_loading);
            Button button=findViewById(R.id.Loading);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(LoadingActivity.this, "正在进入", Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(LoadingActivity.this, MainActivity.class);
                    startActivity(intent);
                }
            });
        }
    }

     

    3.2.1主界面布局代码

    <?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:background="@drawable/main"
        tools:context=".MainActivity"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:gravity="center"
            android:text="电子词典"
            android:textStyle="bold"
            android:textColor="#87CEFA"
            android:textSize="50dp" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <EditText
                android:id="@+id/search_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"
                android:hint="单词"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <Button
                    android:id="@+id/search_btn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:layout_marginBottom="2dp"
                    android:background="#80000000"
                    android:textColor="#FFFFFF"
                    android:text="查询"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                android:id="@+id/btn_add"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"
                android:background="#80000000"
                android:textColor="#FFFFFF"
                android:text="添加" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <Button
                android:id="@+id/btn_delete"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"
                android:background="#80000000"
                android:textColor="#FFFFFF"
                android:text="删除" />
        </LinearLayout>
        </LinearLayout>
        <ListView
            android:id="@+id/result_listView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </LinearLayout>

     

    3.2.2主界面activity代码

    package com.example;

    import androidx.appcompat.app.AppCompatActivity;
    import android.content.Intent;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.view.View;
    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.Map;

    public class MainActivity extends AppCompatActivity {
        private DBOpenHelper dbOpenHelper;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            dbOpenHelper = new DBOpenHelper(MainActivity.this, "db_dict", null, 1);
            final ListView listView = findViewById(R.id.result_listView);
            final EditText etsearch = findViewById(R.id.search_et);
            Button btn_search = findViewById(R.id.search_btn);
            Button btn_add = findViewById(R.id.btn_add);
            Button btn_delete = findViewById(R.id.btn_delete);
            btn_add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(MainActivity.this, AddActivity.class);
                    startActivity(intent);
                }
            });
            btn_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(MainActivity.this, DeleteActivity.class);
                    startActivity(intent);
                }
            });
            btn_search.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String key = etsearch.getText().toString();
                    Cursor cursor = dbOpenHelper.getReadableDatabase().query("tb_dict", null, "word=?", new String[]{key}, null, null, null);
                    ArrayList<Map<String, String>> resultlist = new ArrayList<Map<String, String>>();
                    while (cursor.moveToNext()) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("word", cursor.getString(1));
                        map.put("interpret", cursor.getString(2));
                        resultlist.add(map);
                    }
                    if (resultlist == null || resultlist.size() == 0) {
                        Toast.makeText(MainActivity.this, "很遗憾,没有记录", Toast.LENGTH_LONG).show();
                    } else {
                        SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, resultlist,
                                R.layout.result_main,
                                new String[]{"word", "interpret"}, new int[]{
                                R.id.result_word, R.id.result_interpret});
                        listView.setAdapter(simpleAdapter);
                    }

                }
            });
        }
            protected void onDestroy(){
                super.onDestroy();
                if (dbOpenHelper != null) {
                    dbOpenHelper.close();
                }
            }}

     

    3.3.1添加界面布局代码

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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:background="@drawable/add"
        android:orientation="vertical"
        tools:context="com.example.AddActivity">
        <EditText
            android:id="@+id/add_word"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:hint="单词" />
        <EditText
            android:id="@+id/add_interpret"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:hint="翻译" />
            <Button
                android:id="@+id/save_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"
                android:background="#80000000"
                android:textColor="#FFFFFF"
                android:text="保存" />
            <Button
                android:id="@+id/cancel_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"
                android:background="#80000000"
                android:textColor="#FFFFFF"
                android:text="取消" />
        </LinearLayout>

     

    3.3.2添加界面activity代码

    package com.example;
    import android.content.ContentValues;
    import android.content.Intent;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.os.PersistableBundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    import androidx.annotation.Nullable;
    import androidx.appcompat.app.AppCompatActivity;

    public class AddActivity extends AppCompatActivity {
        private DBOpenHelper dbOpenHelper;
        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_add);
            dbOpenHelper=new DBOpenHelper(AddActivity.this,"db_dict",null,1);
            final EditText etword=findViewById(R.id.add_word);
            final EditText etinterpret=findViewById(R.id.add_interpret);
            Button btn_save=findViewById(R.id.save_btn);
            Button btn_cancel=findViewById(R.id.cancel_btn);
            btn_save.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String word=etword.getText().toString();
                    String interpret=etinterpret.getText().toString();
                    if(word.equals("")||interpret.equals("")){
                        Toast.makeText(AddActivity.this,"填写的单词或解释为空",Toast.LENGTH_SHORT).show();
                    }else{
                        insertData(dbOpenHelper.getReadableDatabase(),word,interpret);
                        Toast.makeText(AddActivity.this,"添加生词成功",Toast.LENGTH_SHORT).show();
                    }
                }
            });
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(AddActivity.this,MainActivity.class);
                    startActivity(intent);
                }
            });
        }
        private void insertData(SQLiteDatabase sqLiteDatabase,String word,String interpret){
            ContentValues values=new ContentValues();
            values.put("word",word);
            values.put("detail",interpret);
            sqLiteDatabase.insert("tb_dict",null,values);
        }
        protected void onDestroy(){
            super.onDestroy();
            if(dbOpenHelper!=null){
                dbOpenHelper.close();
            }}
    }

    3.4.1删除界面布局代码

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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:background="@drawable/delete"
        android:orientation="vertical"
        tools:context="com.example.AddActivity">
        <EditText
            android:id="@+id/delete_word"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:hint="单词" />
        <EditText
            android:id="@+id/delete_interpret"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:hint="翻译" />
        <Button
            android:id="@+id/delete_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:background="#80000000"
            android:textColor="#FFFFFF"
            android:text="删除" />
        <Button
            android:id="@+id/cancel_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp"
            android:background="#80000000"
            android:textColor="#FFFFFF"
            android:text="取消" />
    </LinearLayout>

    3.4.2删除界面activity代码

    package com.example;
    import android.content.Intent;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    import androidx.annotation.Nullable;
    import androidx.annotation.VisibleForTesting;
    import androidx.appcompat.app.AppCompatActivity;

    public class DeleteActivity extends AppCompatActivity {
        private DBOpenHelper dbOpenHelper;
        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_delete);
            dbOpenHelper=new DBOpenHelper(DeleteActivity.this,"db_dict",null,1);
            final EditText scword=findViewById(R.id.delete_word);
            final EditText scinterpret=findViewById(R.id.delete_interpret);
            Button btn_delete=findViewById(R.id.delete_btn);
            Button btn_cancel=findViewById(R.id.cancel_btn);
            btn_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String word=scword.getText().toString();
                    String interpret=scinterpret.getText().toString();
                    if(word.equals("")||interpret.equals("")){
                        Toast.makeText(DeleteActivity.this,"填写的单词或解释为空",Toast.LENGTH_SHORT).show();
                    }else{
                        deleteData(dbOpenHelper.getReadableDatabase(),word,interpret);
                        Toast.makeText(DeleteActivity.this,"删除成功",Toast.LENGTH_SHORT).show();
                    }
                }
            });
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(DeleteActivity.this,MainActivity.class);
                    startActivity(intent);
                }
            });
        }
        private void deleteData(SQLiteDatabase sqLiteDatabase,String word,String interpret){
            sqLiteDatabase.delete("tb_dict","word=?",new String[]{word+""});
        }
        protected void onDestroy(){
            super.onDestroy();
            if(dbOpenHelper!=null){
                dbOpenHelper.close();
            }}
    }

    3.5.1listview显示代码

    <?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="wrap_content"
                android:layout_height="wrap_content"
                android:text="单词:"
                android:textColor="    #000000"
                android:textSize="50dp"/>
            <TextView
                android:id="@+id/result_word"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="    #000000"
                android:textSize="50dp"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="    #000000"
                android:text="翻译:"
                android:textSize="50dp"/>
            <TextView
                android:id="@+id/result_interpret"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="    #000000"
                android:textSize="50dp"/>
        </LinearLayout>
    </LinearLayout>

     

    四、实际测试

    4.1添加测试

     

    4.2查询测试

     

    4.3删除测试

     

     

    五、项目总结

    本文阐述了电子行业的现状、发展历史以及未来的广阔的市场前景、表明了电子词典在词典行业中的重要性、详细讲解了手机电子词典APP的整个开发到实现的过程,以及具体的功能分析、需求分析、工作原理等等。其实我在数据库的创建实现过程中一开始也是遇到了一些困难,不知道该从哪里下手才好。后来找来相关资料仔细钻研学习,最终做出了这个电子词典软件。

  • 相关阅读:
    Java 抽象类 初学者笔记
    JAVA super关键字 初学者笔记
    Java 标准输入流 初学者笔记
    JAVA 将对象引用作为参数修改实例对象参数 初学者笔记
    JAVA 根据类构建数组(用类处理数组信息) 初学者笔记
    JAVA 打印日历 初学者笔记
    Python 测试代码 初学者笔记
    Python 文件&异常 初学者笔记
    Python 类 初学者笔记
    ubuntu网络连接失败
  • 原文地址:https://www.cnblogs.com/xiaohusha/p/12000033.html
Copyright © 2011-2022 走看看