Created
October 9, 2019 20:50
-
-
Save kyodgorbek/0a2edf15ba54a04e66dddc77e68c327c 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 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