基于Android Studio 开辟的浅易记事本

打印 上一主题 下一主题

主题 539|帖子 539|积分 1617

一、高质量源码(非开源,白嫖低价勿扰)

   
关注公众号:《编程乐学》

   
背景复兴:23050901

     同款低价传送链接(仅13.3¥):
  网络资源模板--基于 Android Studio 实现浅易的记事本-CSDN博客
  目录
一、弁言
视频效果展示:
图片效果展示:
二、详细设计
1.首页
2.添加和修改页面
3.登录页
4.注册页
三、获取源码


一、弁言

         Android初学者开辟第一个完备的基础实例项目应该就属《记事本》了,该项目基于Android Studio开辟利用Java语言,该项目包罗SQLlit数据库的利用、listview、等。话不多说先上制品:
视频效果展示:

     Android studio期末设计大作业~记事本App
  图片效果展示:

登录页


注册页 


首页



添加页面​

修改页面




二、详细设计

1.首页

          用户进行笔记添加,利用listview表现笔记。  
        该代码实现了一个记事本应用的主活动(NotepadActivity)。在该活动中,利用了一个ListView来表现便签的列表。重要包罗以下几个部门:

  • onCreate()方法:在该方法中,设置了活动的结构文件(activity_notepad.xml),并初始化了ListView和一个添加按钮(ImageView)。添加按钮的点击变乱监听器被设置为打开另一个活动(RecordActivity)的意图,并在该意图中传递了一个请求码(1)。
  • initData()方法:该方法被调用来初始化数据。在该方法中,清空了列表数据(如果存在),并从SQLite数据库中查询数据,并将查询结果传递给自定义的适配器(NotepadAdapter)。最后,将适配器设置给ListView。
  • showQueryData()方法:该方法用于表现查询的数据。在该方法中,先清空列表数据(如果存在),然后再从SQLite数据库中查询数据,并将查询结果传递给适配器,最后将适配器设置给ListView。
  • onActivityResult()方法:当从另一个活动(RecordActivity)返回时,该方法会被调用。在该方法中,查抄返回的请求码和结果码,如果满意条件,则调用showQueryData()方法来表现查询的数据。
  1. public class NotepadActivity extends Activity {
  2.     ListView listView;
  3.     List<NotepadBean> list;
  4.     SQLiteHelper mSQLiteHelper;
  5.     NotepadAdapter adapter;
  6.     @Override
  7.     protected void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.activity_notepad);
  10.         //用于显示便签的列表
  11.         listView = (ListView) findViewById(R.id.listview);
  12.         ImageView add = (ImageView) findViewById(R.id.add);
  13.         add.setOnClickListener(new View.OnClickListener() {
  14.             @Override
  15.             public void onClick(View v) {
  16.                 Intent intent = new Intent(NotepadActivity.this,
  17.                         RecordActivity.class);
  18.                 startActivityForResult(intent, 1);
  19.             }
  20.         });
  21.         initData();
  22.     }  
  23.     }
  24.     private void showQueryData(){
  25.         if (list!=null){
  26.             list.clear();
  27.         }
  28.         //从数据库中查询数据(保存的标签)
  29.         list = mSQLiteHelper.query();
  30.         adapter = new NotepadAdapter(this, list);
  31.         listView.setAdapter(adapter);
  32.     }
  33.     @Override
  34.     protected void onActivityResult(int requestCode,int resultCode, Intent data){
  35.         super.onActivityResult(requestCode, resultCode, data);
  36.         if (requestCode==1&&resultCode==2){
  37.             showQueryData();
  38.         }
  39.     }
  40. }
复制代码


2.添加和修改页面

        点击首页加号按钮或者点击列表项按钮进行对应的页面跳转。
​       
这段代码是一个Android应用程序中的一部门,用于初始化数据和处理点击变乱。下面对代码进行简要的概括:

  • initData() 方法用于初始化数据。起首创建一个 SQLiteHelper 对象用于操作数据库。然后根据传入的 Intent 对象获取传递过来的数据,并根据数据的有无设置相应的文本内容和可见性。
  • onClick() 方法是一个点击变乱的处理方法。根据点击的控件的id,执行相应的操作。

    • 当点击了id为 note_back 的控件时,调用 finish() 方法结束当前Activity。
    • 当点击了id为 delete 的控件时,将 content 控件的文本内容置空。
    • 当点击了id为 note_save 的控件时,起首获取 content 控件的文本内容,并进行相应的操作。

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


        这段代码的重要目的是根据传入的数据进行新增或修改数据库中的记载,并根据操作结果表现相应的提示信息。
  1. protected void initData() {
  2.         mSQLiteHelper = new SQLiteHelper(this);
  3.         noteName.setText("添加记录");
  4.         Intent intent = getIntent();
  5.         if(intent!= null){
  6.             id = intent.getStringExtra("id");
  7.             if (id != null){
  8.                 noteName.setText("修改记录");
  9.                 content.setText(intent.getStringExtra("content"));
  10.                 note_time.setText(intent.getStringExtra("time"));
  11.                 note_time.setVisibility(View.VISIBLE);
  12.             }
  13.         }
  14.     }
  15.     @Override
  16.     public void onClick(View v) {
  17.         switch (v.getId()) {
  18.             case R.id.note_back:
  19.                 finish();
  20.                 break;
  21.             case R.id.delete:
  22.                 content.setText("");
  23.                 break;
  24.             case R.id.note_save:
  25.                 String noteContent=content.getText().toString().trim();
  26.                 if (id != null){//修改操作
  27.                     if (noteContent.length()>0){
  28.                         if (mSQLiteHelper.updateData(id, noteContent, DBUtils.getTime())){
  29.                             showToast("修改成功");
  30.                             setResult(2);
  31.                             finish();
  32.                         }else {
  33.                             showToast("修改失败");
  34.                         }
  35.                     }else {
  36.                         showToast("修改内容不能为空!");
  37.                     }
  38.                 }else {
  39.                     //向数据库中添加数据
  40.                     if (noteContent.length()>0){
  41.                         if (mSQLiteHelper.insertData(noteContent, DBUtils.getTime())){
  42.                             showToast("保存成功");
  43.                             setResult(2);
  44.                             finish();
  45.                         }else {
  46.                             showToast("保存失败");
  47.                         }
  48.                     }else {
  49.                         showToast("修改内容不能为空!");
  50.                     }
  51.                 }
  52.                 break;
  53.         }
复制代码
3.登录页

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:background="#fb7a6a"
  8.     tools:context=".Login.LoginActivity">
  9.     <LinearLayout
  10.         android:layout_width="300dp"
  11.         android:layout_height="0dp"
  12.         android:gravity="center|top"
  13.         android:orientation="vertical"
  14.         app:layout_constraintBottom_toBottomOf="parent"
  15.         app:layout_constraintEnd_toEndOf="parent"
  16.         app:layout_constraintStart_toStartOf="parent"
  17.         app:layout_constraintTop_toBottomOf="@+id/imageView">
  18.         <EditText
  19.             android:id="@+id/username_edittext"
  20.             android:layout_width="match_parent"
  21.             android:layout_height="wrap_content"
  22.             android:hint="请输入账号"
  23.             android:textSize="20sp" />
  24.         <EditText
  25.             android:id="@+id/password_edittext"
  26.             android:layout_width="match_parent"
  27.             android:layout_height="wrap_content"
  28.             android:layout_marginTop="20dp"
  29.             android:hint="请输入密码"
  30.             android:inputType="textPassword"
  31.             android:textSize="20sp" />
  32.         <Button
  33.             android:id="@+id/login_button"
  34.             android:layout_width="250dp"
  35.             android:layout_height="wrap_content"
  36.             android:layout_marginTop="80dp"
  37.             android:background="@drawable/button"
  38.             android:text="立 即 登 陆"
  39.             android:textColor="#fff"
  40.             android:textSize="14sp" />
  41.         <Button
  42.             android:id="@+id/register_button"
  43.             android:layout_width="250dp"
  44.             android:layout_height="wrap_content"
  45.             android:layout_marginTop="20dp"
  46.             android:background="@drawable/button"
  47.             android:text="立 即 注 册"
  48.             android:textColor="#fff"
  49.             android:textSize="14sp" />
  50.     </LinearLayout>
  51.     <ImageView
  52.         android:id="@+id/imageView"
  53.         android:layout_width="0dp"
  54.         android:layout_height="200dp"
  55.         android:scaleType="centerCrop"
  56.         app:layout_constraintEnd_toEndOf="parent"
  57.         app:layout_constraintHorizontal_bias="0.0"
  58.         app:layout_constraintStart_toStartOf="parent"
  59.         app:layout_constraintTop_toTopOf="parent"
  60.         app:srcCompat="@drawable/logo" />
  61. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码

4.注册页

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:background="#fb7a6a"
  8.     tools:context=".Register.RegisterActivity">
  9.     <LinearLayout
  10.         android:layout_width="300dp"
  11.         android:layout_height="0dp"
  12.         android:gravity="center|top"
  13.         android:orientation="vertical"
  14.         app:layout_constraintBottom_toBottomOf="parent"
  15.         app:layout_constraintEnd_toEndOf="parent"
  16.         app:layout_constraintStart_toStartOf="parent"
  17.         app:layout_constraintTop_toBottomOf="@+id/imageView2">
  18.         <EditText
  19.             android:id="@+id/username_edittext"
  20.             android:layout_width="match_parent"
  21.             android:layout_height="wrap_content"
  22.             android:hint="请输入账号"
  23.             android:textSize="20sp" />
  24.         <EditText
  25.             android:id="@+id/password_edittext"
  26.             android:layout_width="match_parent"
  27.             android:layout_height="wrap_content"
  28.             android:layout_marginTop="20dp"
  29.             android:hint="请输入密码"
  30.             android:inputType="textPassword"
  31.             android:textSize="20sp" />
  32.         <EditText
  33.             android:id="@+id/repeat"
  34.             android:layout_width="match_parent"
  35.             android:layout_height="wrap_content"
  36.             android:layout_marginTop="20dp"
  37.             android:ems="10"
  38.             android:hint="再次输入您的密码"
  39.             android:inputType="textPassword"
  40.             android:textSize="20sp" />
  41.         <TextView
  42.             android:id="@+id/tv_login"
  43.             android:layout_width="match_parent"
  44.             android:layout_height="wrap_content"
  45.             android:layout_marginTop="10dp"
  46.             android:gravity="center|right"
  47.             android:text="已有账号?立即登录"
  48.             android:textColor="#fff"
  49.             android:textSize="15sp" />
  50.         <Button
  51.             android:id="@+id/register_button"
  52.             android:layout_width="250dp"
  53.             android:layout_height="wrap_content"
  54.             android:layout_marginTop="80dp"
  55.             android:background="@drawable/button"
  56.             android:text="立 即 注 册"
  57.             android:textColor="#fff"
  58.             android:textSize="14sp" />
  59.     </LinearLayout>
  60.     <ImageView
  61.         android:id="@+id/imageView2"
  62.         android:layout_width="0dp"
  63.         android:layout_height="200dp"
  64.         android:scaleType="centerCrop"
  65.         app:layout_constraintEnd_toEndOf="parent"
  66.         app:layout_constraintHorizontal_bias="0.0"
  67.         app:layout_constraintStart_toStartOf="parent"
  68.         app:layout_constraintTop_toTopOf="parent"
  69.         app:srcCompat="@drawable/logo" />
  70. </androidx.constraintlayout.widget.ConstraintLayout>
复制代码
三、获取源码

   关注公众号《编程乐学》,背景复兴:23050901
  
  

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

不到断气不罢休

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表