Search code examples
javaandroidandroid-listviewandroid-arrayadapter

What does these three lines of codes mean?


I'm struggling to understand certain lines of code. What do these three lines mean when using an Array Adapter?

WordAdapter itemsAdapter = new WordAdapter(this,words);
ListView listView = findViewById(R.id.numlist);
listView.setAdapter(itemsAdapter);

Solution

    1. WordAdapter itemsAdapter = new WordAdapter(this,words);

      A custom adapter class for adding your listArray(contains data which will be added to List view), Bind view holder class and rest of the things which will provide you customization for displaying data in list view.

    2. ListView listView = findViewById(R.id.numlist);

      ListView is a predefined component class in android sdk, using this class you will create a object reference to the xml declared component ie.. R.id.numlist into your java class file.

    3. listView.setAdapter(itemsAdapter);

      This line attaches the adapter to the listview so that the data in the listarray will be displayed on listview