Main Activity
Main Activity
kt
package com.example.noteapp
import android.app.SearchManager
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.ClipboardManager
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.Toast
import androidx.appcompat.widget.SearchView
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.row.*
import kotlinx.android.synthetic.main.row.view.*
//Load from DB
LoadQuery("%")
}
//Adapter
var myNotesAdapter = MyNotesAdapter (this, listNotes)
//set adapter
notelistview.adapter = myNotesAdapter
//searchView
val sv: SearchView = menu!!.findItem(R.id.app_bar_search).actionView as
SearchView
return super.onCreateOptionsMenu(menu)
}
return super.onOptionsItemSelected(item)
}
sharedBtn.setOnClickListener {
val title = myView.titleTextView.text.toString()
val desc = myView.descTextView.text.toString()
val s = title + "\n"+desc
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.type = "text/plain"
shareIntent.putExtra(Intent.EXTRA_TEXT, s)
startActivity(Intent.createChooser(shareIntent, s))
}
return myView
}
AddNoteActivity.kt
package com.example.noteapp
import android.content.ContentValues
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_add_note.*
import kotlin.Exception
try {
var bundle :Bundle = intent.extras
id = bundle.getInt("ID", 0)
if(id!=0){
//update note
//change actionbar title
supportActionBar!!.title = "Update Note"
//change button text
addBtn.text = "Update"
titleEdit.setText(bundle.getString("name"))
descEdit.setText(bundle.getString("des"))
}
}catch (ex:Exception){}
}
if (id == 0){
val ID = dbManager.insert(values)
if (ID>0){
Toast.makeText(this, "Note is added", Toast.LENGTH_SHORT).show()
}
else{
Toast.makeText(this, "Error adding note...",
Toast.LENGTH_SHORT).show()
}
}
else{
var selectionArgs = arrayOf(id.toString())
val ID = dbManager.update(values, "ID=?", selectionArgs)
if (ID>0){
Toast.makeText(this, "Note is added", Toast.LENGTH_SHORT).show()
finish()
}
else{
Toast.makeText(this, "Error adding note...",
Toast.LENGTH_SHORT).show()
}
}
}
}