基于Android Studio 开发的简易记事本

这篇具有很好参考价值的文章主要介绍了基于Android Studio 开发的简易记事本。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

🍅文章末尾有获取完整项目源码方式🍅

目录

一、引言

视频效果展示:

图片效果展示:

二、详细设计

1.首页

2.添加和修改页面

3.登录页

4.注册页

三、获取源码


一、引言

         Android初学者开发第一个完整的基础实例项目应该就属《记事本》了,该项目基于Android Studio开发使用Java语言,该项目包含SQLlit数据库的使用、listview、等。话不多说先上成品:

视频效果展示:

基于Android Studio 开发的简易记事本

图片效果展示:

登录页

android记事本代码,Android,android studio,android,ide

注册页 

android记事本代码,Android,android studio,android,ide

首页

android记事本代码,Android,android studio,android,ide

添加页面​android记事本代码,Android,android studio,android,ide

修改页面

android记事本代码,Android,android studio,android,ide

二、详细设计

1.首页

          用户进行笔记添加,使用listview显示笔记。  

        该代码实现了一个记事本应用的主活动(NotepadActivity)。在该活动中,使用了一个ListView来显示便签的列表。主要包括以下几个部分:

  1. onCreate()方法:在该方法中,设置了活动的布局文件(activity_notepad.xml),并初始化了ListView和一个添加按钮(ImageView)。添加按钮的点击事件监听器被设置为打开另一个活动(RecordActivity)的意图,并在该意图中传递了一个请求码(1)。

  2. initData()方法:该方法被调用来初始化数据。在该方法中,清空了列表数据(如果存在),并从SQLite数据库中查询数据,并将查询结果传递给自定义的适配器(NotepadAdapter)。最后,将适配器设置给ListView。

  3. showQueryData()方法:该方法用于显示查询的数据。在该方法中,先清空列表数据(如果存在),然后再从SQLite数据库中查询数据,并将查询结果传递给适配器,最后将适配器设置给ListView。

  4. onActivityResult()方法:当从另一个活动(RecordActivity)返回时,该方法会被调用。在该方法中,检查返回的请求码和结果码,如果满足条件,则调用showQueryData()方法来显示查询的数据。

public class NotepadActivity extends Activity {
    ListView listView;
    List<NotepadBean> list;
    SQLiteHelper mSQLiteHelper;
    NotepadAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notepad);
        //用于显示便签的列表
        listView = (ListView) findViewById(R.id.listview);
        ImageView add = (ImageView) findViewById(R.id.add);
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(NotepadActivity.this,
                        RecordActivity.class);
                startActivityForResult(intent, 1);
            }
        });
        initData();
    }  

    }
    private void showQueryData(){
        if (list!=null){
            list.clear();
        }
        //从数据库中查询数据(保存的标签)
        list = mSQLiteHelper.query();
        adapter = new NotepadAdapter(this, list);
        listView.setAdapter(adapter);
    }
    @Override
    protected void onActivityResult(int requestCode,int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==1&&resultCode==2){
            showQueryData();
        }
    }
}

2.添加和修改页面

        点击首页加号按钮或者点击列表项按钮进行对应的页面跳转。

​       

这段代码是一个Android应用程序中的一部分,用于初始化数据和处理点击事件。下面对代码进行简要的概括:

  1. initData() 方法用于初始化数据。首先创建一个 SQLiteHelper 对象用于操作数据库。然后根据传入的 Intent 对象获取传递过来的数据,并根据数据的有无设置相应的文本内容和可见性。

  2. onClick() 方法是一个点击事件的处理方法。根据点击的控件的id,执行相应的操作。

    • 当点击了id为 note_back 的控件时,调用 finish() 方法结束当前Activity。

    • 当点击了id为 delete 的控件时,将 content 控件的文本内容置空。

    • 当点击了id为 note_save 的控件时,首先获取 content 控件的文本内容,并进行相应的操作。

      • 如果 id 不为 null,表示是修改操作。判断内容是否为空,若不为空,则调用 mSQLiteHelper 的 updateData() 方法进行数据库的更新操作,并根据更新结果显示相应的提示信息。
      • 如果 id 为 null,表示是添加操作。判断内容是否为空,若不为空,则调用 mSQLiteHelper 的 insertData() 方法进行数据库的插入操作,并根据插入结果显示相应的提示信息。

        这段代码的主要目的是根据传入的数据进行新增或修改数据库中的记录,并根据操作结果显示相应的提示信息。

 protected void initData() {
        mSQLiteHelper = new SQLiteHelper(this);
        noteName.setText("添加记录");
        Intent intent = getIntent();
        if(intent!= null){
            id = intent.getStringExtra("id");
            if (id != null){
                noteName.setText("修改记录");
                content.setText(intent.getStringExtra("content"));
                note_time.setText(intent.getStringExtra("time"));
                note_time.setVisibility(View.VISIBLE);
            }
        }
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.note_back:
                finish();
                break;
            case R.id.delete:
                content.setText("");
                break;
            case R.id.note_save:
                String noteContent=content.getText().toString().trim();
                if (id != null){//修改操作
                    if (noteContent.length()>0){
                        if (mSQLiteHelper.updateData(id, noteContent, DBUtils.getTime())){
                            showToast("修改成功");
                            setResult(2);
                            finish();
                        }else {
                            showToast("修改失败");
                        }
                    }else {
                        showToast("修改内容不能为空!");
                    }
                }else {
                    //向数据库中添加数据
                    if (noteContent.length()>0){
                        if (mSQLiteHelper.insertData(noteContent, DBUtils.getTime())){
                            showToast("保存成功");
                            setResult(2);
                            finish();
                        }else {
                            showToast("保存失败");
                        }
                    }else {
                        showToast("修改内容不能为空!");
                    }
                }
                break;
        }

3.登录页

<?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="#fb7a6a"
    tools:context=".Login.LoginActivity">

    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="0dp"
        android:gravity="center|top"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView">

        <EditText
            android:id="@+id/username_edittext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入账号"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/password_edittext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:hint="请输入密码"
            android:inputType="textPassword"
            android:textSize="20sp" />

        <Button
            android:id="@+id/login_button"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="80dp"
            android:background="@drawable/button"
            android:text="立 即 登 陆"
            android:textColor="#fff"
            android:textSize="14sp" />

        <Button
            android:id="@+id/register_button"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:background="@drawable/button"
            android:text="立 即 注 册"
            android:textColor="#fff"
            android:textSize="14sp" />

    </LinearLayout>

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:scaleType="centerCrop"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/logo" />
</androidx.constraintlayout.widget.ConstraintLayout>

4.注册页

<?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="#fb7a6a"
    tools:context=".Register.RegisterActivity">

    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="0dp"
        android:gravity="center|top"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView2">

        <EditText
            android:id="@+id/username_edittext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入账号"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/password_edittext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:hint="请输入密码"
            android:inputType="textPassword"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/repeat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:ems="10"
            android:hint="再次输入您的密码"
            android:inputType="textPassword"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/tv_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center|right"
            android:text="已有账号?立即登录"
            android:textColor="#fff"
            android:textSize="15sp" />

        <Button
            android:id="@+id/register_button"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="80dp"
            android:background="@drawable/button"
            android:text="立 即 注 册"
            android:textColor="#fff"
            android:textSize="14sp" />

    </LinearLayout>

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:scaleType="centerCrop"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/logo" />
</androidx.constraintlayout.widget.ConstraintLayout>

三、获取源码

关注公众号《编程乐学》,后台回复:23050901

👇👇​​​​​​​👇​​​​​​​快捷获取方式👇👇👇文章来源地址https://www.toymoban.com/news/detail-753180.html

到了这里,关于基于Android Studio 开发的简易记事本的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • android studio大作业,android studio课程设计,记事本实现

    先看效果图 功能点实现: 登录,注册,记事本分类添加,删除,数据分析统计报表,数据库使用SQLlite 部分实现代码

    2024年02月11日
    浏览(45)
  • Android开发_记事本(1)

    TextView中有下述几个属性: id: 为TextView设置一个组件id,根据id,我们可以在Java代码中通过findViewById()的方法获取到该对象,然后进行相关属性的设置,又或者使用RelativeLayout时,参考组件用的也是id! layout_width: 组件的宽度,一般写: wrap_content 或者 match_parent(fill_parent) ,前

    2023年04月10日
    浏览(56)
  • 基于安卓系统(android)记事本APP管理系统设计与实现

    目录 摘要 I Abstract II 1 绪论 1.1 课题来源、目的和意义 1 1.2 国内外基本研究情况 1 2 需求分析 2.1 用户需求 4 2.2 功能需求 4 2.3 数据库选择 6 2.4 性能需求 6 3 概要设计 3.1 功能概要设计 7 3.2 数据库概要设计 13 4 详细设计 4.1 功能设计 15 4.2 数据库设计 30 5 系统功能实现 5.1 系统架

    2024年02月11日
    浏览(32)
  • Android:实现安卓小程序-记事本(备忘录)的开发,教你如何增加拿到BAT大厂offer几率

    public MyBaseAdapter(Context context, List data) { this.context = context; this.data = data; } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return 0; } @Override public int getCount() { if(data==null) return 0; return data.size(); } } 接着在编写NoteAdapter类继承上类,初始化view, 将Note条目的

    2024年04月25日
    浏览(41)
  • Android记事本

    1、项目需求分析 1.1、记事功能需求分析: 1.1.1、显示记事 用户打开记事本可以看到之前所写的所有记事内容,进入主页后,软件应该从数据库中搜索出该用户所写的全部记事,并将所有的数据进行显示。 1.1.2、添加记事 设置添加按钮,点击添加按钮之后可以编辑记事的标题

    2024年02月03日
    浏览(44)
  • Android——记事本功能业务(完整代码)

    目录 实现效果 一、搭建记事本页面布局activity_notepad.xml 二、搭建记事本界面Item布局notepad_item_layout.xml 三、封装记录信息实体类NotepadBean类 四、编写记事本界面列表适配器NotepadAdapter类 五、创建数据库 六、实现记事本界面的显示功能NotepadAdapter.java  七、搭建添加记录界面和

    2024年02月03日
    浏览(57)
  • Android 备忘录,记事本程序设计

    android备忘录实现,使用ObjectBox数据库框架进行数据存储,增删改查等操作。代码使用kotlin编写。 1、下面看看ObjectBox数据库封装 需要注意的是:    /**      * 你只有配置好之后, 点击 Make Model \\\'你的model名字\\\', 才会创建 MyObjectBox对象      * 对于MyObjectBox的包名, 目前我发现的

    2024年01月23日
    浏览(38)
  • 微信小程序开发笔记—记事本

    其实在一开始本人就想做一个类似日记本的功能,但是碍于最开始能力有限,而且发现上网搜索到的一些相关资料较少,看到做有其他博主做,但是使用的云开发,本人暂时只想做一个简单的无后台的,所以没有参考。其次也搜到一些其他内容,真的是看了超多文章,这里贴

    2024年02月03日
    浏览(39)
  • 【Android 记事本,笔记本,可注册登录,增删改查(附源码)】

    简介 用Sqlite做数据库,用来存储账号以及笔记信息,实现了账号的注册以及登录功能,笔记方面实现了新增、删除、修改、搜索功能,列表展示笔记使用的是listView(懒得弄分割线,就使用listView的默认分割线了); 运行效果 代码讲解 我代码里使用了两个依赖,一个是工具

    2024年02月04日
    浏览(39)
  • 安卓大作业(AndroidStudio开发)日记记事本app

    博主介绍: 本人专注于Android/java/数据库/微信小程序技术领域的开发,以及有好几年的计算机毕业设计方面的实战开发经验和技术积累;尤其是在安卓(Android)的app的开发和微信小程序的开发,很是熟悉和了解;本人也是多年的Android开发人员;希望我发布的此篇文件可以帮

    2024年02月11日
    浏览(44)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包