

The default SelectionModel used when instantiating a ListView is an implementation of the MultipleSelectionModel abstract class. GetFocusModel().getFocusedItem() – Returns the currently focused item

GetFocusModel().getFocusedIndex() – Returns the index of the currently focused item GetSelectionModel().getSelectedItem() – Returns the currently selected item GetSelectionModel().getSelectedIndex() – Returns the index of the currently selected items in a single-selection mode To obtain the current state of each item, use a combination of the following methods:

DataModel.Description of "Figure 11-3 Horizontal List View Control"Īt any time, you can track the selection and focus of the ListView object with the SelectionModel and FocusModel classes. The data model that is contained in the ArrayList is shown below. The content_main.xml contains the ListView as shown below. getView() is the method that returns the actual view used as a row within the ListView at a particular position. We are creating a custom ListView of by subclassing ArrayAdapter with the DataModel as the object. Clicking the info will display a SnackBar with information specific to that row. Clicking the row would display the SnackBar with the text elements of that row. In this tutorial we’ll build an application that consists of list of rows displaying text descriptions and an info icon.

Let’s create a xml layout that presents the items in a row in a customised way. As the user scrolls through the list, items that leave the screen are kept in memory for later use and then every new row that enters the screen reuses an older row kept in the memory. After that no new row items are created in the memory. Recycling RowsĪs a ListView is instantiated and the rows are populated such that the full height of the list is filled. There are other adapters as well, such as the CursorAdapter which binds directly to a result set from a Local SQLite Database and it uses a Cursor as it’s data source. That’s what we’ll implement in this tutorial. The simplest Adapter to populate a view from an ArrayList is the ArrayAdapter. Also to enhance the user experience, we’ll animate the ListView while scrolling. In this tutorial we’ll use a CustomAdapter that populates the custom rows of the Android ListView with an ArrayList.
