当前位置: 首页 > article >正文

网络资源模板--Android Studio 实现记事本App

目录

一、项目演示

二、项目测试环境

三、项目详情

四、完整的项目源码 


一、项目演示

网络资源模板--基于Android studio 实现的记事本App

二、项目测试环境

三、项目详情

首页

  1. 显示笔记列表:使用 ListView 显示从数据库中查询到的笔记内容。
  2. 搜索功能:通过 SearchView 允许用户根据笔记内容进行实时搜索,过滤并更新显示的笔记列表。
  3. 添加新笔记:通过点击一个图标 (addRecord),用户可以进入 RecordActivity 界面,添加新的笔记。
  4. 删除笔记:长按某条笔记会弹出确认对话框,用户可以选择删除该笔记,删除后更新列表。
  5. 查看笔记详情:单击某条笔记会进入 RecordActivity,显示该笔记的详细信息。
  6. 数据更新:在返回主界面时会刷新笔记列表,确保显示的是最新数据。
   // 设置长按事件监听器,用于删除笔记
        listView.setOnItemLongClickListener((adapterView, view, position, id) -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(NotePadActivity.this);
            builder.setMessage("是否删除此记录") // 设置对话框信息
                    .setPositiveButton("确定", (dialog, which) -> {
                        Note note = noteList.get(position); // 获取长按的笔记
                        noteList.remove(note); // 从列表中删除笔记
                        adapter.notifyDataSetChanged(); // 刷新适配器
                        new NotepadDao(NotePadActivity.this).deleteById(note.getId()); // 从数据库删除
                    })
                    .setNegativeButton("取消", (dialog, which) -> dialog.dismiss()) // 取消按钮
                    .show(); // 显示对话框
            return true;
        });

        // 设置单击事件监听器,用于查看笔记详情
        listView.setOnItemClickListener((adapterView, view, position, id) -> {
            Intent intent = new Intent(NotePadActivity.this, RecordActivity.class); // 创建意图
            Note note = noteList.get(position); // 获取被点击的笔记
            intent.putExtra("id", note.getId()); // 传递笔记ID
            intent.putExtra("content", note.getContent()); // 传递笔记内容
            intent.putExtra("noteTime", note.getNoteTime()); // 传递笔记时间
            intent.putExtra("cate", note.getCate()); // 传递分类
            intent.putExtra("tag", note.getTag()); // 传递标签
            startActivityForResult(intent, 1); // 启动新活动
        });

修改页面

开发一个 Android 应用中的 NotePadActivity 类,主要实现笔记的增、删、查功能,并使用 ListView 和 SearchView。最近,用户询问了如何解决 NullPointerException,尤其是在字符串比较时。用户展示了添加分类和标签的对话框代码,并进行了一些优化建议,包括提取通用方法、使用异常处理、在更新适配器时调用 notifyDataSetChanged(),以及确保适配器不为空。

// 显示添加分类对话框
    private void showAddCategoryDialog() {
        showAddDialog("请输入分类名称", (name) -> {
            if (TextUtils.isEmpty(name)) {
                Toast.makeText(this, "输入为空!", Toast.LENGTH_SHORT).show(); // 输入为空提示
                return;
            }
            CateDao cateDao = new CateDao(this);
            cateDao.insertCate(name); // 插入新分类
            cateArrayList = cateDao.queryCate(); // 更新分类列表
            categorySpinner.setAdapter(new ArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item, cateArrayList)); // 更新下拉框适配器
            Toast.makeText(this, "已添加", Toast.LENGTH_SHORT).show(); // 显示添加成功提示
        });
    }

    // 显示添加标签对话框
    private void showAddTagDialog() {
        showAddDialog("请输入标签名称", (name) -> {
            if (TextUtils.isEmpty(name)) {
                Toast.makeText(this, "输入为空!", Toast.LENGTH_SHORT).show(); // 输入为空提示
                return;
            }
            TagDao tagDao = new TagDao(this);
            tagDao.insertTag(name); // 插入新标签
            tagArrayList = tagDao.queryTag(); // 更新标签列表
            tagSpinner.setAdapter(new ArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item, tagArrayList)); // 更新下拉框适配器
            Toast.makeText(this, "已添加", Toast.LENGTH_SHORT).show(); // 显示添加成功提示
        });
    }

添加页面

  1. 笔记管理:支持新增、删除和查看笔记。
  2. 列表展示:使用 ListView 显示笔记。
  3. 搜索功能:通过 SearchView 进行笔记搜索。
  4. 分类与标签:允许用户为笔记添加分类和标签
 // 如果ID为空,执行插入操作
            notepadDao.insertData(content,
                    cateArrayList.get(categorySpinner.getSelectedItemPosition()).getContent(),
                    tagArrayList.get(tagSpinner.getSelectedItemPosition()).getContent(), time);
            Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).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"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="70.0dip"
        android:background="#fffb7a6a">

        <ImageView
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:paddingLeft="10.0dip"
            android:src="@drawable/back" />

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="添加记录"
            android:textColor="#ffffffff"
            android:textSize="30.0sp" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_record_time"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="5.0dip"
            android:text="2020年1月1日"
            android:textColor="#fffb7a6a"
            android:visibility="gone" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="分类:" />

        <Spinner
            android:id="@+id/catespinner"
            android:layout_width="100.0dip"
            android:layout_height="50.0dip"
            android:layout_weight="1.0" />

        <ImageView
            android:id="@+id/addcate"
            android:layout_width="30.0dip"
            android:layout_height="30.0dip"
            android:layout_weight="1.0"
            app:srcCompat="@drawable/add" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="标签:" />

        <Spinner
            android:id="@+id/tagspinner"
            android:layout_width="100.0dip"
            android:layout_height="50.0dip"
            android:layout_weight="1.0" />

        <ImageView
            android:id="@+id/addtag"
            android:layout_width="30.0dip"
            android:layout_height="30.0dip"
            android:layout_weight="1.0"
            app:srcCompat="@drawable/add" />
    </LinearLayout>

    <EditText
        android:id="@+id/et_content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.0"
        android:gravity="start"
        android:hint="请输入要添加的内容" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="60.0dip"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/delete"
            android:layout_width="0.0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:src="@drawable/delete" />

        <ImageView
            android:id="@+id/saveNote"
            android:layout_width="0.0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:src="@drawable/save_note" />
    </LinearLayout>
</LinearLayout>

四、完整的项目源码 

👇👇👇👇👇快捷获取方式👇👇👇👇👇


http://www.kler.cn/news/350911.html

相关文章:

  • 数据结构:堆的应用
  • 软考(中级-软件设计师)计算机系统篇(1024)
  • 微信小程序/uniapp动态修改tabBar信息及常见报错
  • 合约门合同全生命周期管理系统:企业合同管理的数字化转型之道
  • Python量化交易(二):金融市场的基础概念
  • 力扣2528.最大化城市的最小电量
  • 2025推荐选题|基于MVC的农业病虫害防治平台的设计与实现
  • MongoDB oplog 详解
  • Shiro(认证Authentication)
  • [含文档+PPT+源码等]精品基于Python实现的flask美甲线上预约系统
  • ubuntu20.04运行ORB_SLAM2
  • 010_django基于spark的电力能耗数据分析系统的设计与实现2024_s120960s
  • FPGA实现PCIE采集电脑端视频转SFP光口UDP输出,基于XDMA+GTX架构,提供4套工程源码和技术支持
  • Python中的HTTP高手:如何玩转requests模块
  • 高级java每日一道面试题-2024年10月13日-数据库篇[Redis篇]-怎么保证缓存和数据库数据的一致性?
  • golang从http请求中读取xml格式的body,并转成json
  • [LeetCode] 733. 图像渲染
  • el-date-picker选择时间后标准时间少1小时问题
  • HTML 标签简写及全称
  • 编写自定义dbt通用数据测试
  • 2.Node.js 缓冲器(Buffer)
  • Excel:vba实现批量修改文件名
  • 【pytorch】昇思大模型配置python的conda版本
  • Elasticsearch:Redact(编辑) processor
  • 地级市-节能环保支出数据(2007-2021年)
  • Java之泛型详解