Guest User

Untitled

a guest
May 15th, 2020
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. package com.example.jurajsolarml.simpleapp
  2.  
  3. import android.content.Intent
  4. import android.os.Bundle
  5. import android.view.Menu
  6. import android.view.MenuItem
  7. import android.widget.Toast
  8. import androidx.appcompat.app.AppCompatActivity
  9. import androidx.core.view.GravityCompat
  10. import androidx.recyclerview.widget.LinearLayoutManager
  11. import androidx.recyclerview.widget.RecyclerView
  12. import com.google.android.material.navigation.NavigationView
  13.  
  14.  
  15. class ContactsDetail : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
  16.  
  17. private var layoutManager: RecyclerView.LayoutManager? = null
  18. private var adapter: RecyclerView.Adapter<RecyclerAdapter.ViewHolder>? = null
  19.  
  20. override fun onCreate(savedInstanceState: Bundle?) {
  21. super.onCreate(savedInstanceState)
  22. setContentView(R.layout.activity_contacts_detail)
  23. setSupportActionBar(toolbar)
  24.  
  25. layoutManager = LinearLayoutManager(this)
  26. recyclerView.layoutManager = layoutManager
  27. adapter = RecyclerAdapter()
  28. recyclerView.adapter = adapter
  29. var userList: ArrayList<String> = arrayListOf(" Janko Hraško", "Milan Boss", "Ján Cap", "Daniel Vlk", "Iveta Milá", "Ján Vlk", "Samo Bohatý", "Marcel Chalupa", "Erik Chalupa")
  30.  
  31. val toggle = ActionBarDrawerToggle(this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
  32. drawer_layout.addDrawerListener(toggle)
  33. toggle.syncState()
  34. nav_view.setNavigationItemSelectedListener(this)
  35.  
  36. }
  37.  
  38. override fun onBackPressed() {
  39. //This method is added to handle situations whereby
  40. //the activity has a “back” button to return to a previous activity screen.
  41. if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
  42. drawer_layout.closeDrawer(GravityCompat.START)
  43. } else {
  44. super.onBackPressed()
  45. }
  46. }
  47.  
  48. override fun onCreateOptionsMenu(menu: Menu): Boolean {
  49. // Inflate the menu_contacts_detail; this adds items to the action bar if it is present.
  50. menuInflater.inflate(R.menu.menu_search, menu)
  51. return true
  52. }
  53.  
  54. override fun onOptionsItemSelected(item: MenuItem): Boolean {
  55. // Handle action bar item clicks here. The action bar will
  56. // automatically handle clicks on the Home/Up button, so long
  57. // as you specify a parent activity in AndroidManifest.xml.
  58. return when (item.itemId) {
  59. R.id.search_bar -> true
  60. else -> super.onOptionsItemSelected(item)
  61.  
  62. }
  63. }
  64.  
  65. override fun onNavigationItemSelected(item: MenuItem): Boolean {
  66. // Handle navigation view item clicks here.
  67. when (item.itemId) {
  68. R.id.navDetailCon_MainMenu -> {
  69. val intent = Intent(this, MenuMain::class.java)
  70. startActivity(intent)
  71.  
  72. }
  73. R.id.navDetailCon_map -> {
  74. val intent = Intent(this, MapsActivity::class.java)
  75. startActivity(intent)
  76.  
  77. }
  78. R.id.navDetailCon_help -> {
  79. Toast.makeText(this, "Čoskoro :))", Toast.LENGTH_SHORT).show()
  80.  
  81. }
  82.  
  83. }
  84.  
  85. drawer_layout.closeDrawer(GravityCompat.START)
  86. return true
  87. }
  88. }
Add Comment
Please, Sign In to add comment