From c1d5a3e8fb8b3f8ac28d1e7818b5b33c0ab41b49 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Wed, 17 Feb 2021 22:57:15 +0100 Subject: Recycler view now working in a fragment. --- app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt index 17d124e..ac585c7 100644 --- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt @@ -1,13 +1,13 @@ package xyz.adjutor.aniki import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button -import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController +import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class TopMangaPage : Fragment() { @@ -17,7 +17,16 @@ class TopMangaPage : Fragment() { savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment - return inflater.inflate(R.layout.top_manga_page, container, false) + val view = inflater.inflate(R.layout.top_manga_page, container, false) + + // Retrieves data from mangasource + val mangaList = MangaSource(view.context).getMangaList() + + val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view) + recyclerView.setHasFixedSize(true) + recyclerView.layoutManager = LinearLayoutManager(view.context) + recyclerView.adapter = MangaAdapter(mangaList) + return view } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -27,11 +36,5 @@ class TopMangaPage : Fragment() { findNavController().navigate(R.id.action_TopMangaPage_to_HomePage) } - // Retrieves data from mangasource - val mangaList = MangaSource(requireActivity().applicationContext).getMangaList() - - val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view) - recyclerView.adapter = MangaAdapter(mangaList) - } } \ No newline at end of file -- cgit v1.2.3