Created
September 13, 2019 22:03
-
-
Save De-Morgan/a8390de3a9a77347a10a9e33bdb7d14c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsOverviewFragment : Fragment() { | |
lateinit var binding: PostsOverviewFragmentBinding | |
private val postViewModel: PostsOverviewViewModel by lazy{ | |
ViewModelProviders.of(this).get(PostsOverviewViewModel::class.java) | |
} | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
binding = PostsOverviewFragmentBinding.inflate(inflater) | |
binding.setLifecycleOwner(this) | |
val postListAdapter = PostListAdapter() | |
binding.viewModel = postViewModel | |
binding.postsList.adapter = postListAdapter | |
postViewModel.post.observe(this, Observer { | |
it?.let{ | |
postListAdapter.data = it | |
} | |
}) | |
return binding.root | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment