Skip to content

Instantly share code, notes, and snippets.

@merttoptas
Created December 15, 2019 17:29
Show Gist options
  • Save merttoptas/8b76107f5e018bb4ca026ec34a501ae8 to your computer and use it in GitHub Desktop.
Save merttoptas/8b76107f5e018bb4ca026ec34a501ae8 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Create a notes in list
val notes:List<Note>
val db:AppDatabase= Room.databaseBuilder(this,AppDatabase::class.java,"notes")
.allowMainThreadQueries()
.fallbackToDestructiveMigration()
.build()
//Get a notes
notes=db.notedao().getAllNotes()
//set adapter
recyclerview.layoutManager= LinearLayoutManager(this)
recyclerview.adapter=NoteAdapter(notes,this@MainActivity)
fab.setOnClickListener {
val intent= Intent(this,CreateNoteActivity::class.java)
startActivity(intent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment