Lecture 7
Lecture 7
• Resource: It is used to set the layout file(.xml files) for the list items.
• public ArrayAdapter(this, R.layout.itemListView, int textViewResourceId, T[] objects)
• objects: These are the array object which is used to set the array element into the
TextView.
• ArrayAdapter arrayAdapter = new ArrayAdapter(this, R.layout.itemListView, R.id.itemTextView,
courseList[]);
Example
getCount()
This method will return the number of rows present in the listview.
It will give us number of cells in the case of gridview.
We can use data source like arraylist to check the total number of data items and then return this
number.
Methods of Custom Array Adapter
getItem(int position)
• This method will return the data at the specified position.
• For example, a hashmap from arraylist of hashmap at the specified position will be
returned by this method.
getItemId()
• This method will return the specific id associated with the data set.
getItemViewType(int position)
• Listview can have more than two types of row.
• For example, a header row, sub header row, normal child row, footer row etc.
• When compiler is creating the every row of listview, there should be something which tells
it type of the row.