Android实现记事本功能

首先声明,本人是android的小白,主要是新人项目写了这个程序,思路可能不是很清晰,可优化的地方也有很多,望路过的大佬不吝赐教。
该记事本包含创建新条目,数据库增删改查,条目可编辑,滑动删除与拖拽排序,简单闹钟实现(还有个简陋背景音乐开关就不提了太简单),接下来逐一介绍一下。

build.gradle导入

apply plugin: 'kotlin-kapt'
'''
implementation 'com.google.android.material:material:1.0.0'
    implementation 'de.hdodenhof:circleimageview:3.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'androidx.room:room-runtime:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    kapt "androidx.room:room-compiler:2.1.0"

没什么多说的。。。

Room数据库

room数据库相比于sqlite来说对新人确实友好很多,在没有SQL基础的前提下,增删改查等实现都很简单,只需创建一个实例,便可在线程中进行。具体代码为
①接口:

@Dao
interface NoteDao {
   


    @Update
    fun updateNote(newNote: Note)

    @Query("select * from Note")
    fun loadAllNotes(): List<Note>

    @Query("select * from Note where title > :title")
    fun loadNotesLongerThan(title:String) : List<Note>

    @Query("select * from Note where id == :id")
    fun loadById(id:Long) :Note

    @Delete
    fun deleteNote(note: Note)

    @Query("delete from Note where title == :title")
    fun deleteNoteByTitle(title: String): Int

    @Insert
    fun insertNote(note: Note)


}


②Appdatabase类(获取实例

@Database(version = 1, entities = [Note::class])
abstract class AppDatabase: RoomDatabase(){
   

    abstract fun noteDao() : NoteDao

    companion object{
   
        //访问实例
        private var instance : AppDatabase? = null

        @Synchronized//同步化
        fun getDatabase(context: Cont
  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值