How to call another view, Im using Leanback with kotlin

47 Views Asked by At

I dontknow how to call another view, Im devoloping an app for smart tv, the technologies are android,kotlin and leanback library, I trying to do click in my cardview called "Lecciones" when i clicked there i need to call to my view Lesson

this is my code

class MainActivity : FragmentActivity() {


    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)




        /**   binding.button2.setOnClickListener {
        val intent = Intent(this, EaActivity::class.java)
        startActivity(intent)

        }
         */
    }
}

data class Content(var title: String, var poster: String)
class MainFragment : BrowseSupportFragment() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)


        title = getString(R.string.browse_title)

        val rowsAdapter = ArrayObjectAdapter(ListRowPresenter())


        val categoryTitles = listOf(
            "LECCIONES",
            "EJEMPLOS",
            "EJERCICIOS",
            "EVALUACIÓN"
        )


        val titlesPerCategory = 1

        onItemViewClickedListener = OnItemViewClickedListener { _, item, _, _ ->
            val intent = Intent(requireContext(), Lesson::class.java).apply {
                // pass the item information
            }
            startActivity(intent)


        }

        (1..4).forEach { categoryId ->
            val categoryTitle = categoryTitles[categoryId - 1]

            val listRowAdapter = ArrayObjectAdapter(CardPresenter())

            listRowAdapter.addAll(0, (1..titlesPerCategory).map { index ->
                val title = generateTitle(categoryId, index)
                Content(
                    title,
                    "https://c.pxhere.com/images/15/da/2135fc8acd22bb3f6ae67c79fe53-1449505.jpg!d"

                )

            })
            val header = HeaderItem(categoryId.toLong(), categoryTitle)
            rowsAdapter.add(ListRow(header, listRowAdapter))




            adapter = rowsAdapter


        }


        onItemViewClickedListener = OnItemViewClickedListener { _, item, _, _ ->
            val intent = Intent(requireContext(), Lesson::class.java)
            startActivity(intent)
        }


    }

    fun generateTitle(categoryId: Int, index: Int): String {
        return when (categoryId) {
            1 -> "Lección  - $index"
            2 -> "Ejemplo - $index"
            3 -> "Ejercicio - $index"
            4 -> "Evaluación $index"
            else -> "Título Categoría Desconocida - $index"
        }
    }
}

i need call the other view, the other view is FragmentBrowser, the class call lesson

0

There are 0 best solutions below