Day61 of #100DaysOfCode

Kushagra Kesav
2 min readApr 8, 2022

--

#CodeTogether Day 61/100

Hii folks 🙌

Today I will be continuing the same pathway in which I will learn to update the Fragments label.

Unit 3: Navigation

Pathway 2: Introduction to the Navigation component

Source: https://developer.android.com/courses/android-basics-kotlin/course

  • Now we will get the Arguments in WordListFragment by creating a letterId property. We can mark this as lateinit so that we don't have to make it nullable.
private lateinit var letterId: String
  • Then override onCreate() (not onCreateView() or onViewCreated()!), add the following.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
letterId = it.getString(LETTER).toString()
}
}

Because it’s possible for arguments to be optional, we will call let() and pass in a lambda. This code will execute assuming arguments is not null, passing in the non-null arguments for the it parameter. If arguments is null, however, the lambda will not execute.

  • Finally, we can access the letterId when we set the recycler view's adapter. Replace activity?.intent?.extras?.getString(LETTER).toString() in onViewCreated() with letterId.
recyclerView.adapter = WordAdapter(letterId, requireContext())

Now we will run the app. It’s now able to navigate between two screens, without any intents, and all in a single activity.

That is all for Day61 ✅

Thanks for reading, See you tomorrow!

If you are reading my #100Days Journey, feel free to drop by ;)

--

--