天天看點

Android記事本 (附apk和源碼)

Android記事本 基于資料庫

    • 工程下載下傳
    • 功能簡介
    • 操作示範
    • 部分代碼展示

工程下載下傳

Gitee 下載下傳位址 點選跳轉(源碼及apk)

百度雲 下載下傳位址 點選跳轉 提取碼:uksb

CSDN 下載下傳 點選跳轉 (apk)

CSDN 下載下傳 點選跳轉 (項目源碼)

功能簡介

本項目是由Android Studio編寫的一個安卓記事本軟體,記事本功能包括——建立新筆記,檢視筆記,修改筆記,删除筆記等基礎功能,其中筆記通過資料庫儲存,重新開機不丢失。

操作示範

這是一個Android Studio 模拟器,當然你也可以在真機上測試

Android記事本 (附apk和源碼)

打開程式 這裡的軟體名為 Notepad

Android記事本 (附apk和源碼)

這裡是主界面,可以點選下方的建立圖示建立筆記

Android記事本 (附apk和源碼)

輸入筆記内容,點選下方的儲存即可儲存筆記。

Android記事本 (附apk和源碼)
Android記事本 (附apk和源碼)

點選之前儲存的筆記可以檢視和修改筆記

Android記事本 (附apk和源碼)

建立新筆記儲存成功後會提示儲存成功

Android記事本 (附apk和源碼)

長按筆記可選擇删除筆記。

Android記事本 (附apk和源碼)

旁邊的電源鍵可以鎖屏,和真機差不多啦

Android記事本 (附apk和源碼)

部分代碼展示

主界面布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fefefe">
    <TextView
        android:id="@+id/note_name"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:textSize="20sp"
        android:textColor="@android:color/white"
        android:gravity="center"
        android:textStyle="bold"
        android:background="#fb7a6a"
        android:text="記事本"/>
    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:cacheColorHint="#00000000"
        android:divider="#E4E4E4"
        android:dividerHeight="1dp"
        android:fadingEdge="none"
        android:listSelector="#00000000"
        android:scrollbars="none"
        android:layout_below="@+id/note_name">
    </ListView>
    <ImageView
        android:id="@+id/add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/add"
        android:layout_marginBottom="30dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>
           

主界面對應的代碼

package cn.itcast.notepad;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.List;

import cn.itcast.notepad.adapter.NotepadAdapter;
import cn.itcast.notepad.bean.NotepadBean;
import cn.itcast.notepad.database.SQLiteHelper;

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();
    }
    protected void initData() {
        mSQLiteHelper= new SQLiteHelper(this); //建立資料庫
        showQueryData();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent,View view,int position,long id){
                NotepadBean notepadBean = list.get(position);
                Intent intent = new Intent(NotepadActivity.this, RecordActivity.class);
                intent.putExtra("id", notepadBean.getId());
                intent.putExtra("time", notepadBean.getNotepadTime()); //記錄的時間
                intent.putExtra("content", notepadBean.getNotepadContent()); //記錄的内容
                NotepadActivity.this.startActivityForResult(intent, 1);
            }
        });
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, final int
                    position, long id) {
                AlertDialog dialog;
                AlertDialog.Builder builder = new AlertDialog.Builder( NotepadActivity.this)
                        .setMessage("是否删除此事件?")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                NotepadBean notepadBean = list.get(position);
                                if(mSQLiteHelper.deleteData(notepadBean.getId())){
                                    list.remove(position);
                                    adapter.notifyDataSetChanged();
                                    Toast.makeText(NotepadActivity.this,"删除成功",
                                            Toast.LENGTH_SHORT).show();
                                }
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                dialog =  builder.create();
                dialog.show();
                return true;
            }
        });

    }
    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();
        }
    }
}
           

如果有需要可以點選文章開始的連結下載下傳工程檔案,如果下載下傳失敗,需要付費,需要積分啥的。請告知我。

好,感謝觀看,收藏不迷路,記得點贊呀。