Skip to content

Instantly share code, notes, and snippets.

@merttoptas
Created December 15, 2019 18:45
Show Gist options
  • Save merttoptas/faf7433e4dcaf75e10126c8238e8b1c4 to your computer and use it in GitHub Desktop.
Save merttoptas/faf7433e4dcaf75e10126c8238e8b1c4 to your computer and use it in GitHub Desktop.
class CreateNoteActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_create_note)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
val db:AppDatabase= Room.databaseBuilder(applicationContext,AppDatabase::class.java,"notes")
.allowMainThreadQueries()
.fallbackToDestructiveMigration()
.build()
btn_Add.setOnClickListener {
if(txt_Title.text!!.isEmpty() || _txt_Subject.text!!.isEmpty() || txt_description.text!!.isEmpty()){
Toast.makeText(applicationContext, "Empty!!", Toast.LENGTH_SHORT).show()
}else{
val note:Note= Note(txt_Title.text.toString(),_txt_Subject.text.toString(),txt_description.text.toString())
db.notedao().insertAll(note)
startActivity(Intent(this@CreateNoteActivity,MainActivity::class.java))
finish()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment