How to update layout contain after API is been called in PagerAdapter - android

I have created viewpager layout in which i am passing three different layout which need be update when any API is been called all three any time whether that page is been selected or not.
MainActivity.java
int[] layouts = new int[]{R.layout.one, R.layout.two, R.layout.three};
MyAdapter adapter = new MyAdapter(this, layouts);
MyAdapter.java
it is been extends to PagerAdapter
View view = layoutInflator.inflate(mLayouts[position], container, false);
container.addView(view);
How to initialize of all the id of different layout and how I can update the text or layout when API is been called.

Please try this way according to your requirement you can also create 3 childFragment with different layout and add them in list
class MyFragment : Fragment{
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return super.onCreateView(inflater, container, savedInstanceState)
initPager()
}
var fragmentAdapter: PagerAdapter? = null
fun initPager() {
fragmentAdapter = PagerAdapter(
childFragmentManager)
val fragment1 = ChildFragment("1")
fragmentAdapter!!.addFragment(fragment1,"title")
val fragment2 = ChildFragment("2")
fragmentAdapter!!.addFragment(fragment2,"title")
val fragment3 = ChildFragment("3")
fragmentAdapter!!.addFragment(fragment3,"title")
viewPager.adapter = fragmentAdapter
viewPager.offscreenPageLimit = 3
viewPager.addOnPageChangeListener(object :
ViewPager.OnPageChangeListener {
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
}
override fun onPageSelected(position: Int) {
// do this instead, assuming your adapter reference
// is named mAdapter:
for (page in childFragmentManager.fragments) {
val frag: Fragment = fragmentAdapter!!.getItem(position)
if (frag != null && frag is ChildFragment && page is ChildFragment) {
page.refresh()
}
}
}
override fun onPageScrollStateChanged(state: Int) {}
})
}
}
class PagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
private val mFragmentList = ArrayList<Fragment>()
private val mFragmentTitleList = ArrayList<String>()
val activeFragment: List<Fragment>
get() = mFragmentList
override fun getItem(position: Int): Fragment {
return mFragmentList[position]
}
override fun getCount(): Int {
return mFragmentList.size
}
fun addFragment(fragment: Fragment, title: String) {
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}
override fun getPageTitle(position: Int): CharSequence? {
return mFragmentTitleList[position]
}
}
class ChildFragment : Fragment{
var type:String = ""
constructor(type:String){
this.type = type
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return super.onCreateView(inflater, container, savedInstanceState)
if(type.equals("")){
//TODO LAYOUT LOGIC here according to type validation
}else{
//TODO LAYOUT LOGIC here according to type validation
}
refresh()
}
fun refresh() {
//TODO CALL API and update your layoyt here
}
}

Related

Null bundle in fragment

I am writing a simple Kotlin app and I want to send data from LessonsModule1Fragment to DetailsFragment and try to pass bundle variables. Depending on the position, the fragment should be inflated with the appropriate layout.
I'm trying to pass a position between fragments, but I always get null
LessonsModule1Fragment
class LessonsModule1Fragment : Fragment(), OnLessonClickListener {
private var layoutManager: RecyclerView.LayoutManager? = null
private var adapter: RecyclerView.Adapter<RecyclerViewLessonAdapter.ViewHolder>? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val binding = inflater.inflate(R.layout.fragment_module1_lessons, container, false)
val recyclerView = binding.findViewById<RecyclerView>(R.id.lesson_recycler_view)
layoutManager = LinearLayoutManager(context)
recyclerView.layoutManager = layoutManager
adapter = RecyclerViewLessonAdapter(this)
recyclerView.adapter = adapter
return binding
}
override fun lessonClick(lesson: Lesson, position: Int) {
var bundle = Bundle()
bundle.putInt("POSITION", position)
var transaction = this.parentFragmentManager.beginTransaction()
var fragment = DetailsFragment()
fragment.arguments = bundle
transaction.replace(R.id.lesson_recycle_layout, fragment).commit()
findNavController().navigate(R.id.action_lessonsModule1Fragment_to_detailsFragment)
}
DetailsFragment
class DetailsFragment : Fragment() {
private var num: Int? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
num = arguments?.getInt("POSITION")
when (num) {
0 -> return inflater.inflate(R.layout.fragment_details, container, false)
1 -> return inflater.inflate(R.layout.fragment_details2, container, false)
2 -> return inflater.inflate(R.layout.fragment_details3, container, false)
}
return inflater.inflate(R.layout.fragment_details, container, false)
}}
RecyclerViewLessonAdapter
class RecyclerViewLessonAdapter (private val lessonClickListener: OnLessonClickListener) : RecyclerView.Adapter<RecyclerViewLessonAdapter.ViewHolder>() {
private val lessons = DataStorage.getLessonsList()
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val itemTitle: TextView = itemView.findViewById(R.id.lesson_title)
val itemDetails: TextView = itemView.findViewById(R.id.lesson_description)
val itemImage: ImageView = itemView.findViewById(R.id.lesson_image)
fun lessonBind(lesson: Lesson, clickListener: OnLessonClickListener) {
itemView.setOnClickListener {
clickListener.lessonClick(lesson, adapterPosition)
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.lesson_card, parent, false)
return ViewHolder(v)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.itemImage.setImageResource(lessons[position].images)
holder.itemTitle.text = lessons[position].title
holder.itemDetails.text = lessons[position].details
val lesson = lessons[position]
holder.lessonBind(lesson, lessonClickListener)
}
override fun getItemCount() = lessons.size
}
OnLessonClickListener
interface OnLessonClickListener {
fun lessonClick(lesson: Lesson, position: Int)
}
Perhaps there is a more suitable way?
I used navigation arguments, added these lines and it worked. Thanks for the hint
val action = LessonsModule1FragmentDirections.actionLessonsModule1FragmentToDetailsFragment(position)
findNavController().navigate(action)

How can I add ListView in Fragment using TabLayout?

I am really new at Kotlin. I tried to make slidable pages using TabLayout. I have 3 different Fragments and I need to add ListView or RecyclerView on that fragments but in this point I can't figure out where is I have to add adapter of ListView. I add adapter class on fragment's Kotlin file but I can't connect that and fragment.(I think) I got an error which is ListView cannot be null so I can say about my adapter didn't working correctly. How can I solve it?
Here I add my codes:
My SecondFragment.kt code:
class SecondFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val listView = view!!.findViewById<ListView>(R.id.main_listview)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val listView = view!!.findViewById<ListView>(R.id.main_listview)
return inflater.inflate(R.layout.fragment_second, container, false)
}
private class MyCustomAdapter(context: Context): BaseAdapter(){
private val mContext : Context
private val names = arrayListOf<String>("Test Name", "Steve Jobs", "Tim Cook", "Kobe King")
init {
mContext = context
}
// BURADA KAC TANE ROW OLDUGUNUN SOYLER..
override fun getCount(): Int {
return names.size
}
override fun getItem(position: Int): Any {
return "Test String"
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
//val textView = TextView(mContext)
//textView.text = "Here my first row for list view.."
//return textView
val layoutInflater = LayoutInflater.from(mContext)
val rowMain = layoutInflater.inflate(R.layout.row_for_list, parent, false)
val nameTextView = rowMain.findViewById<TextView>(R.id.name_textView)
nameTextView.text = names.get(position)
val positionTextView = rowMain.findViewById<TextView>(R.id.position_textview)
positionTextView.text = "Row Number: $position"
return rowMain
}
}
}
Here my ViewPagerAdapter.kt file code:
class ViewPagerAdapter(supportFragmentManager: FragmentManager) : FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
private val mFragmentList = ArrayList<Fragment>()
private val mFragmentTitleList = ArrayList<String>()
override fun getCount(): Int {
return mFragmentList.size
}
override fun getItem(position: Int): Fragment {
return mFragmentList[position]
}
override fun getPageTitle(position: Int): CharSequence? {
return mFragmentTitleList[position]
}
fun addFragment(fragment: Fragment, title: String){
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}
}
And here my MainActivity.kt file code:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setUpTabs()
}
private fun setUpTabs() {
val adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(HomeFragment(), "Home")
adapter.addFragment(SecondFragment(), "Second")
adapter.addFragment(ThirdFragment(), "Third")
viewPager.adapter = adapter
tabs.setupWithViewPager(viewPager)
tabs.getTabAt(0)!!.setIcon(R.drawable.ic_baseline_account_box_24)
tabs.getTabAt(1)!!.setIcon(R.drawable.ic_baseline_add_ic_call_24)
tabs.getTabAt(2)!!.setIcon(R.drawable.ic_baseline_adb_24)
}
}
You have to set to instantiate the adapter and set it to the listView, I also explained some things in the comments.
class SecondFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//don't do this in onCreate, do it in onViewCreated or onCreateView
//val listView = view!!.findViewById<ListView>(R.id.main_listview)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val root = inflater.inflate(R.layout.fragment_second, container, false)
//you can set adapter here if you want, but i did it in onViewCreated
//return it
return root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
//get reference to ListView
val listView = root.findViewById<ListView>(R.id.main_listview)
//set adapter
listView.adapter = MyCustomAdapter(requireContext())
}
private class MyCustomAdapter(private val mContext: Context): BaseAdapter(){
//do initiation here as it needs to be done only once
private val layoutInflater: LayoutInflater = LayoutInflater.from(mContext)
private val names = arrayListOf<String>("Test Name", "Steve Jobs", "Tim Cook", "Kobe King")
// BURADA KAC TANE ROW OLDUGUNUN SOYLER..
override fun getCount(): Int {
return names.size
}
override fun getItem(position: Int): Any {
return "Test String"
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
//val textView = TextView(mContext)
//textView.text = "Here my first row for list view.."
//return textView
val rowMain = layoutInflater.inflate(R.layout.row_for_list, parent, false)
val nameTextView = rowMain.findViewById<TextView>(R.id.name_textView)
nameTextView.text = names.get(position)
val positionTextView = rowMain.findViewById<TextView>(R.id.position_textview)
positionTextView.text = "Row Number: $position"
return rowMain
}
}
}
Try this :
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view=inflater.inflate(R.layout.fragment_second, container, false)
val listView = view!!.findViewById<ListView>(R.id.main_listview)
val myListAdapter = MyCustomAdapter(container!!.context)
listView.adapter = myListAdapter
return view
}

How to remove first view pager item in kotlin?

I use View-Pager2 in my application that Which displays several same fragments. I also have a dialog fragment and inside it, I manage view pager items(add and remove items). Every fragment inside the view-pager has an id that saved in the SQLite database.
So, My problem is, When I remove the first item of view-pager, It does not delete and still remains but another item removed and when I launch the app again, I see the first item has been removed and everything is ok.
Main Activity Class:
class MainActivity : AppCompatActivity() {
private lateinit var databaseHelper: DatabaseHelper
private lateinit var myPagerAdapter: MyPagerAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
databaseHelper = DatabaseHelper(this)
myPagerAdapter = MyPagerAdapter(supportFragmentManager, lifecycle)
view_pager.adapter = myPagerAdapter
if (databaseHelper.getCount().toInt() == 0) {
//red
databaseHelper.insertData(0, Color.argb(255, 244, 67, 54))
//blue
databaseHelper.insertData(1, Color.argb(255, 33, 150, 243))
//green
databaseHelper.insertData(2, Color.argb(255, 76, 175, 80))
}
btn_show.setOnClickListener {
val ft = supportFragmentManager.beginTransaction()
ft.add(FragmentTwo(), "Dialog")
ft.addToBackStack(null)
ft.commit()
}
}
private inner class MyPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :
FragmentStateAdapter(fragmentManager, lifecycle) {
override fun getItemCount(): Int {
return databaseHelper.getCount().toInt()
}
override fun createFragment(position: Int): Fragment {
return FragmentOne.newInstance(position)
}
}
fun setViewPagerPosition(position: Int) {
view_pager.currentItem = position
}
fun setViewPagerChanged() {
myPagerAdapter.notifyDataSetChanged()
}
}
FragmentOne class:
class FragmentOne : Fragment() {
companion object {
fun newInstance(position: Int): FragmentOne {
val fragment = FragmentOne()
val bundle = Bundle()
bundle.putInt("id", position)
fragment.arguments = bundle
return fragment
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_one, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val databaseHelper = DatabaseHelper(context)
val id = arguments?.getInt("id")
frame_frag1?.setBackgroundColor(databaseHelper.getColor(id))
}
}
FragmentTwo class (dialog fragment):
class FragmentTwo : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_dialog, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val databaseHelper = DatabaseHelper(context)
btn_remove?.setOnClickListener {
(context as MainActivity).setViewPagerPosition(2)
databaseHelper.deleteData("0")
databaseHelper.updateRowsRemoveTab(id)
(context as MainActivity).setViewPagerChanged()
}
}
}
And its DatabaseHelper class:
class DatabaseHelper(context: Context?) : SQLiteOpenHelper(context, "tabs.db", null, 1) {
private val TBL_NAME: String = "tabs"
override fun onCreate(db: SQLiteDatabase?) {
db?.execSQL("CREATE TABLE $TBL_NAME (ID INTEGER , COLOR INTEGER)")
}
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
db?.execSQL("DROP TABLE IF EXISTS $TBL_NAME")
onCreate(db)
}
fun insertData(id: Int, color: Int) {
val db = this.writableDatabase
val cv = ContentValues()
cv.put("ID", id)
cv.put("COLOR", color)
db.insert(TBL_NAME, null, cv)
}
fun getColor(id: Int?): Int {
val db = this.readableDatabase
var color = 0
val cursor = db.rawQuery("select COLOR from $TBL_NAME where ID = $id", null)
if (cursor.moveToFirst())
do {
color = (cursor.getInt(0))
} while (cursor.moveToNext())
return color
}
fun updateRowsRemoveTab(id: Int) {
val db = this.writableDatabase
db.execSQL("update tabs set ID = ID-1 where ID > $id")
}
fun deleteData(id: String) {
val db = this.writableDatabase
db.delete(TBL_NAME, "ID = ?", arrayOf(id)).toLong()
}
fun getCount(): Long {
val db = this.readableDatabase
val count = DatabaseUtils.queryNumEntries(db, TBL_NAME)
db.close()
return count
}
}
Can you help me?
I do your do without viewpager2 and it ok. I copy your codes and just edit your view pager adapter to this:
private inner class MyPagerAdapter(fragmentManager: FragmentManager) :
FragmentPagerAdapter(fragmentManager) {
override fun getItem(position: Int): Fragment {
return FragmentOne.newInstance(position)
}
override fun getCount(): Int {
return databaseHelper.getCount().toInt()
}
override fun getItemPosition(`object`: Any): Int {
return PagerAdapter.POSITION_NONE
}
}
Dont forget to add PagerAdapter.POSITION_NONE to getItemPosition method.
This way is correct but I don't know how to do this with viewpager2.

viewpager,recylerview not working if using same fragment for all tabs

i am using the same fragment for all the tabs.
But the problem is scroll of the recycler view of fragment working for last tab only.
Recycler view not scrolling for the previous tabs.
Below is my code of the FragmentPagerAdapter:
class DataViewPagerAdapter(fm: FragmentManager?) : FragmentStatePagerAdapter(fm) {
var fragmentList: MutableList<Fragment> = ArrayList()
var fragmentTitleList: MutableList<String> = ArrayList()
override fun getItem(position: Int): Fragment {
return DataFragment.newInstance(position)
}
override fun getCount(): Int {
return 3
}
override fun getPageTitle(position: Int): CharSequence? {
return "Deepak"
}
}
Here is my code for binding adapter:
var adapter = DataViewPagerAdapter( getChildFragmentManager())
dataViewpager.adapter = adapter
dataViewpager.offscreenPageLimit=1
tabLayout.setupWithViewPager(dataViewpager)
This is code of my fragment:
class DataFragment : Fragment() {
lateinit var recyclerView: RecyclerView
companion object {
fun newInstance(position: Int): DataFragment {
val fragment = DataFragment()
val args = Bundle()
args.putInt("KEY_POSITION", position)
args.putInt("KEY_ID",1)
fragment.setArguments(args)
return fragment
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var view = LayoutInflater.from(activity).inflate(R.layout.fragment_data, null)
recyclerView = view.findViewById<RecyclerView>(R.id.recyclerView)
var adapter = DataFragmentAdapter()
recyclerView.layoutManager = GridLayoutManager(activity, 3)
recyclerView.adapter = adapter
return view;
}
}
I'm not sure if it's related to your problem but offscreenPageLimit should be the size of your adapter count.

kotlin Android studio listView in Fragment

The listview shows in the first fragment properly, that is the first screen of my app.
but if I put the list view in another fragment that is not the first screen of the app. The app will shut down when i click other fragments.
Please kindly help to solve this issue.
here with my code of FourFragment:
class FourFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_four, container, false)
}
var adapter:TutorialAdapter? = null
var listOfTutorial = TutorialList().list
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapter = TutorialAdapter(context!!, mylist = listOfTutorial)
tutorialListView.adapter = adapter
}
fun openYoutubeLink(youtubeID: String) {
val intentApp = Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + youtubeID))
val intentBrowser = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + youtubeID))
try {
this.startActivity(intentApp)
} catch (ex: ActivityNotFoundException) {
this.startActivity(intentBrowser)
}
}
inner class TutorialAdapter : BaseAdapter {
var mylist=ArrayList<Tutorial>()
var context: Context?=null
constructor(context: Context, mylist:ArrayList<Tutorial>):super() {
this.context=context
this.mylist=mylist
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
val tutorialget = mylist[position]
var inflater = context!!.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
var myView = inflater.inflate(R.layout.tutorial_layout,null)
myView.title.text = tutorialget.name
myView.youtubeIcon.setImageResource(tutorialget.image!!)
myView.youtubeIcon.setOnClickListener {
openYoutubeLink(youtubeID = tutorialget.youtubeLink!!)
}
return myView
}
override fun getItem(position: Int): Any {
return mylist[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getCount(): Int {
return mylist.size
}
}
}
Here with my code of MainActivity:
class MainActivity : AppCompatActivity() {
private var tabLayout: TabLayout? = null
var viewPager: ViewPager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Action Bar
val actionBar = supportActionBar
actionBar!!.setDisplayShowHomeEnabled(true)
actionBar.setBackgroundDrawable(ColorDrawable(Color.parseColor("#00FFFFFF")))
actionBar.setIcon(R.drawable.title)
actionBar.setDisplayShowTitleEnabled(false)
viewPager = findViewById(R.id.viewpager) as ViewPager
setupViewPager(viewPager!!)
tabLayout = findViewById(R.id.tabs) as TabLayout
tabLayout!!.setupWithViewPager(viewPager)
val headerView = (getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
.inflate(R.layout.custom_tab, null, false)
val linearLayoutOne = headerView.findViewById(R.id.ll) as LinearLayout
val linearLayout2 = headerView.findViewById(R.id.ll2) as LinearLayout
val linearLayout3 = headerView.findViewById(R.id.ll3) as LinearLayout
val linearLayout4 = headerView.findViewById(R.id.ll4) as LinearLayout
tabLayout!!.getTabAt(0)!!.setCustomView(linearLayoutOne)
tabLayout!!.getTabAt(1)!!.setCustomView(linearLayout2)
tabLayout!!.getTabAt(2)!!.setCustomView(linearLayout3)
tabLayout!!.getTabAt(3)!!.setCustomView(linearLayout4)
}
private fun setupViewPager(viewPager: ViewPager) {
val adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(OneFragment(), "ONE")
adapter.addFragment(TwoFragment(), "TWO")
adapter.addFragment(ThreeFragment(), "THREE")
adapter.addFragment(FourFragment(), "FOUR")
viewPager.adapter = adapter
}
internal inner class ViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
private val mFragmentList = ArrayList<Fragment>()
private val mFragmentTitleList = ArrayList<String>()
override fun getItem(position: Int): Fragment {
return mFragmentList[position]
}
override fun getCount(): Int {
return mFragmentList.size
}
fun addFragment(fragment: Fragment, title: String) {
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}
override fun getPageTitle(position: Int): CharSequence {
return mFragmentTitleList[position]
}
}
}
your ListView instance is null. You should instantiate tutorialListView inside onCreateView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view: View = inflater.inflate(R.layout.fragment_four, container, false)
tutorialListView = view.findViewById<ListView>(R.id.recycler_view)
return view
}

Categories

Resources