July 2018
Intermediate to advanced
266 pages
7h 11m
English
Now we have an adapter that can map a List<Article> into views. We just need to use this adapter in conjunction with the RecyclerView that we added to the main activity.
For this, we will need some variables in our MainActivity class:
class MainActivity : AppCompatActivity() { ... private lateinit var articles: RecyclerView private lateinit var viewAdapter: ArticleAdapter private lateinit var viewManager: RecyclerView.LayoutManager ...}
We will instantiate all of them inside the onCreate() function:
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) viewManager = LinearLayoutManager(this) viewAdapter = ArticleAdapter() articles ...
Read now
Unlock full access