Skip to content

Instantly share code, notes, and snippets.

@kyodgorbek
Created October 9, 2019 20:50
Show Gist options
  • Save kyodgorbek/0a2edf15ba54a04e66dddc77e68c327c to your computer and use it in GitHub Desktop.
Save kyodgorbek/0a2edf15ba54a04e66dddc77e68c327c to your computer and use it in GitHub Desktop.
class TopHeadlinesFragment : Fragment() {
var topHeadlinesAdapter: TopHeadlinesAdapter? = null
//3
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(
R.layout.fragment_top_headlines
, container, false
)
val recyclerView = view.findViewById (R.id.recyclerView) as RecyclerView
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = topHeadlinesAdapter
val apiInterface = SportNewsInterface.create().getNews()
apiInterface.enqueue(object : Callback<SportNewsResponse> {
override fun onResponse(
call: Call<SportNewsResponse>?,
response: Response<SportNewsResponse>?
) {
if (response?.body() != null) topHeadlinesAdapter?.setMovieListItems(response.body()!!.articles)
}
override fun onFailure(call: Call<SportNewsResponse>?, t: Throwable?) {
}
})
return view
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment