Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    Why the note pages can't show up and can't sync

    Android
    2
    3
    60
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • locus jim
      locus jim last edited by avan

      My purpose: I am using Realm as a database and I am making a note app .I suppose note page can be saved and there is new info (a new column) in the mainActivity .However , after clicking the Save button in the action bar . These can't work but no error is made .
      What files I have? 1.RealmBasicConfig 2.AddSaveNotesActivity 3.NotesAdapter 4.notes_rv_layout (for the pre-set first note view) 5.MainActivity( The first page in the app )

      What solutions I want : why notes_rv_layout does not work , and the notes content can not be synced It should be the problem of the mainActivity ( adapter!!.notifyDataSetChanged - can't work ?)

      The codes of MainActivity:

      class Main2Activity : AppCompatActivity() {
          private lateinit var notesList:ArrayList<BasicInfoConfig>
          private lateinit var realm: Realm
          private lateinit var appBarConfiguration: AppBarConfiguration
      
      
      
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContentView(R.layout.activity_main2)
              handleIntent(intent)
              val toolbar: Toolbar = findViewById(R.id.toolbar)
              setSupportActionBar(toolbar)
      
              val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
              val navView: NavigationView = findViewById(R.id.nav_view)
              val navController = findNavController(R.id.nav_host_fragment)
              // Passing each menu ID as a set of Ids because each
              // menu should be considered as top level destinations.
              appBarConfiguration = AppBarConfiguration(setOf(
                      R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow), drawerLayout)
              setupActionBarWithNavController(navController, appBarConfiguration)
              navView.setupWithNavController(navController)
      
              //custom init views
              realm  = Realm.getDefaultInstance()
      
      
      
              //set onclicklistener
              addNotes.setOnClickListener{
                  startActivity(Intent(this,AddSaveNotesActivity::class.java))
                  finish()
      
              notesRV.layoutManager = LinearLayoutManager(this)
              getAllNotes()
              }
      
          }
      
          private fun getAllNotes() {  //yellow : used
              notesList = ArrayList()
              val  results:RealmResults<BasicInfoConfig> = realm.where<BasicInfoConfig>(BasicInfoConfig::class.java).findAll()
              notesRV.adapter = NotesAdapter(this,results)
              notesRV.adapter!!.notifyDataSetChanged()   // to update   // bec  I deleted the way it saved // none info can be read
          }
      
          override fun onNewIntent(intent: Intent) {
              super.onNewIntent(intent)
      
              handleIntent(intent)
          }
      
      
          override fun onCreateOptionsMenu(menu: Menu): Boolean {
              // Inflate the menu; this adds items to the action bar if it is present.
              menuInflater.inflate(R.menu.main2, menu)
              // Associate searchable configuration with the SearchView
              // Associate searchable configuration with the SearchView
              val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
              (menu.findItem(R.id.search).actionView as SearchView).apply {
                  setSearchableInfo(searchManager.getSearchableInfo(componentName))
              }
              return true
          }
      
          override fun onBackPressed() {
      
              super.onBackPressed()
          }
      
          override fun onSupportNavigateUp(): Boolean {
              val navController = findNavController(R.id.nav_host_fragment)
              return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
          }
          private fun handleIntent(intent: Intent) {
      
              if (Intent.ACTION_SEARCH == intent.action) {
               val query = intent.getStringExtra(SearchManager.QUERY)
                  //use the query to search your data somehow
              }
          }
      }
      
      

      The codes of NotesAdapterView

      class NotesAdapter (private val context : Context? , private  val notesList : RealmResults<BasicInfoConfig>)
          : RecyclerView.Adapter<RecyclerView.ViewHolder>(){
      
          override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
              val v = LayoutInflater.from(parent.context).inflate(R.layout.notes_rv_layout, parent,false)
              return ViewHolder(v)
          }
      
          override fun getItemCount(): Int {
              return notesList.size
          }
      
          override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
                  holder.itemView.notes_title.text = notesList[position]!!.title
                  holder.itemView.notes_body.text = notesList[position]!!.description
      
      
          }
          class  ViewHolder(v:View?):RecyclerView.ViewHolder(v!!) {
              //
              val Ada_title = itemView.findViewById<TextView>(R.id.notes_title)
              val Ada_date = itemView.findViewById<TextView>(R.id.notes_timeStamp)
          }
      The codes of RealmBasicConfig:
      
      package com.example.notepad_free
      
      import io.realm.RealmObject
      import io.realm.annotations.PrimaryKey
      
      open class BasicInfoConfig(
      //connecting  basic info to Realm
          @PrimaryKey
      
      var id:Int ?= null,
      var title:String?=null,
      var description:String?=null
      
      
      ):RealmObject()
      

      Please tell me if more codes are needed , feel grateful if you help!

      android-recyclerview realm android-studio-3.0

      Reply Quote 0
        1 Reply Last reply

      • locus jim
        locus jim last edited by

        is this website forcing me to post the pic , wtf? There 's only a little space for me to see my editing .

        Reply Quote 0
          1 Reply Last reply

        • avan
          avan last edited by

          Wish I could help @locus-jim

          but I am not great at android.

          Reply Quote 0
            1 Reply Last reply

          • First post
            Last post