Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – I created horizontal cards but they arent showing in my fragments?

Posted on November 11, 2022 By

Solution 1 :

Check if this works. If not, post the issue you face after this change.

class MainActivity : AppCompatActivity() {

    private lateinit var horizontalViewAdapter: HorizontalViewAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val navView: BottomNavigationView = findViewById(R.id.nav_view)
        val navController = findNavController(R.id.nav_host_fragment)
        val appBarConfiguration = AppBarConfiguration(setOf(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
        setupActionBarWithNavController(navController, appBarConfiguration)
        navView.setupWithNavController(navController)
        initRecyclerView()
        addDataSet()
    }

    private fun initRecyclerView(){
        val recycler_view = findNavController(R.id.nav_host_fragment)
        recycler_view.apply {
            var layoutManager = LinearLayoutManager([email protected])
            val topSpacingDecorator = TopSpacingItemDecoration(30)
            addItemDecoration(topSpacingDecorator)
            horizontalViewAdapter = HorizontalViewAdapter()
            recycler_view.adapter = horizontalViewAdapter
        }
    }

    private fun addDataSet(){
        val data = DataSource.createDataSet()
        horizontalViewAdapter.updateData(data)
    }

    private fun addItemDecoration(topSpacingDecorator: TopSpacingItemDecoration) {}
}

HorizontalViewAdapter:

class HorizontalViewAdapter {

    fun updateData(data) {
        this.data = data

        // Notify that the data is changed
        notifyDataSetChanged()
    }

    // Everything else
}

Problem :

I tried to create horizontal RecyclerView and Bottom Navigation View.
I made horizontal_card_item.xml, HorizontalView.kt (class), DataSource.kt , and HorizontalViewAdapter File, for recyclerView.

Main Activity.kt:

class MainActivity : AppCompatActivity() {

    private lateinit var horizontalViewAdapter: HorizontalViewAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val navView: BottomNavigationView = findViewById(R.id.nav_view)
        val navController = findNavController(R.id.nav_host_fragment)
        val appBarConfiguration = AppBarConfiguration(setOf(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
        setupActionBarWithNavController(navController, appBarConfiguration)
        navView.setupWithNavController(navController)
        initRecyclerView()
        addDataSet()
    }

    private fun initRecyclerView(){
        val recycler_view = null
        recycler_view.apply {
            var layoutManager = LinearLayoutManager([email protected])
            val topSpacingDecorator = TopSpacingItemDecoration(30)
            addItemDecoration(topSpacingDecorator)
            horizontalViewAdapter = HorizontalViewAdapter()
            var adapter = horizontalViewAdapter
        }
    }

    private fun addDataSet(){
        val data = DataSource.createDataSet()
        //  HorizontalViewAdapter.SubmitList(data)
    }

    private fun addItemDecoration(topSpacingDecorator: TopSpacingItemDecoration) {}
}

Error:

E/RecyclerView: No adapter attached; skipping layout
E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1

Comments

Comment posted by ZSergei

Why you set

Comment posted by Goodie123

Plus I dont think you need the “var” before the adapter, it already knows that adapter variable exists.

Comment posted by Riddhi Dua

Because ‘findViewById’ is showing an error ‘Not enough information to infer type variable T’ @ZSergei

Comment posted by Riddhi Dua

Using this [adapter = horizontalViewAdapter] shows an error in adapter of [Unresolved reference: adapter] @Goodie123

READ  [FIXED] How to adapt Noise Reduction Audacity C++ code to android
Powered by Inline Related Posts

Comment posted by Goodie123

val recyclerView: RecyclerView = findViewById(R.id.recycler_view_id) and then do the apply without the val. It doesnt know what type of variable it is.

Comment posted by Riddhi Dua

unresolved reference for [adapter] and [createDataSet()]

Comment posted by chat.stackoverflow.com/rooms/215419/abhis-chat-room

@RiddhiDua Please add the new error in the question. Possibly with the error line. We can continue our conversation here :

Android Tags:android

Post navigation

Previous Post: [FIXED] android – How to achieve ionic permissions on first load
Next Post: [FIXED] android – How do i put online database into local database

Related Posts

[FIXED] Android + iOS – Install + Run / Run an app from a WWW link with specified parameters Android
[FIXED] android – Altbeacon not detecting if app was killed Android
[FIXED] android – editText.getText().append in fragment is not working Android
[FIXED] android – How can I get the longitude and lattitude of a specific address not the current address Android
[FIXED] android – Service onCreate() is not being called Android
[FIXED] android – Why does the same native thread appear to call methods from different Java threads? Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme