Android studio java generated
ArrayAdapter arrayAdapter = new ArrayAdapter(this, int resource, int textViewResourceId, T objects)
Android studio java generated code#
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.