

The third parameter is textViewResourceId which is used to set the id of TextView where you want to display the actual text.īelow is the example code in which we set the id(identity) of a text view. ArrayAdapter arrayAdapter = new ArrayAdapter(this, R.layout.list_view_items, int textViewResourceId, T objects) The second parameter is resource id used to set the layout( xml file) for list items in which you have a text view.īelow is the example code in which we set the layout. ArrayAdapter arrayAdapter = new ArrayAdapter(this, int resource, int textViewResourceId, T objects) getApplicationContext() is used in a Activity and getActivity() is used in a Fragment.īelow is the example code in which we set the current class reference in a adapter. We can also use getApplicationContext(), getActivity() in the place of this keyword. Here this is a keyword used to show the current class reference. The first parameter is used to pass the context means the reference of current class. Lets discuss parameter in ArrayAdapter class: Below is the description of all the parameters used for the implementation of a ArrayAdapter to show a list of elements in a list view or in a spinner. In the above code snippet is the implementation of a ArrayAdapter. Here is code of ArrayAdapter in Android: ArrayAdapter(Context context, int resource, int textViewResourceId, T objects) By doing this we can override all the function’s of BaseAdapter in our custom adapter. Important Note: ArrayAdapter is an implementation of BaseAdapter so if we need to create a custom list view or a grid view then we have to create our own custom adapter and extend ArrayAdapter in that custom class.

ArrayAdapter is more simple and commonly used Adapter in android.

It holds the data and send the data to adapter view then view can takes the data from the adapter view and shows the data on different views like listview, gridview, spinner etc. In android, An adapter is a bridge between UI component and data source that helps us to fill data in UI component.
