Android記事本 (附apk和源碼)

Android記事本 基於數據庫

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

工程下載

Gitee 下載地址 點擊跳轉(源碼及apk)

百度雲 下載地址 點擊跳轉 提取碼:uksb

CSDN 下載 點擊跳轉 (apk)

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

功能簡介

本項目是由Android Studio編寫的一個安卓記事本軟件,記事本功能包括——創建新筆記,查看筆記,修改筆記,刪除筆記等基礎功能,其中筆記通過數據庫保存,重啟不丟失。

操作演示

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

打開程序 這裡的軟件名為 Notepad

這裡是主界面,可以點擊下方的創建圖標創建筆記

輸入筆記內容,點擊下方的保存即可保存筆記。

點擊之前保存的筆記可以查看和修改筆記

創建新筆記保存成功後會提示保存成功

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

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

部分代碼展示

主界面佈局

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

如果有需要可以點擊文章開始的鏈接下載工程文件,如果下載失敗,需要付費,需要積分啥的。請告知我。

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

本文來自網絡,不代表程式碼花園立場,如有侵權,請聯系管理員。https://www.codegarden.cn/article/31355/
返回顶部