java.lang.Object | ||||||
↳ | android.content.Context | |||||
↳ | android.content.ContextWrapper | |||||
↳ | android.view.ContextThemeWrapper | |||||
↳ | android.app.Activity | |||||
↳ | sofia.app.Screen | |||||
↳ | sofia.app.ListScreen<E> |
Known Direct Subclasses |
ListScreen
is a subclass of screen that provides a built-in
ListView and convenience methods for manipulating the list directly
in the screen class instead of having to call getListView()
for
every operation.
The ListScreen
class is generic, so users who extend it should
include the type of the items that will be stored in the list so that
methods like add
and remove
will have the correct types. For
example,
public class MyListScreen extends ListScreen<MyObject> { ...
Please see the documentation for ListView for more information on how arbitrary objects are displayed in the list.
When you subclass ListScreen
, by default it will create a new
ListView
that occupies the entire width and height of the screen.
If this is not what you want (for example, if you want to have a
ListView
alongside other widgets but still retain the convenience
of methods like add(E)
directly on the screen), then place an
instance of ListView
in your layout file with the ID
listView
. Then the ListScreen
will use that view for all
of its other methods instead of creating its own.
Note to developers coming from the traditional Android API: though similar,
ListScreen
is not a subclass of ListActivity
, and it does
not have exactly the same functionality or interface.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.app.Activity
| |||||||||||
From class
android.content.Context
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.app.Activity
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ListScreen() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
boolean |
add(E item)
Adds an item to the list view.
| ||||||||||
void |
add(int index, E item)
Inserts an item into the list view at the specified index.
| ||||||||||
boolean |
addAll(Collection<? extends E> collection)
Adds the items in the specified collection to the list view.
| ||||||||||
boolean |
addAll(int index, Collection<? extends E> collection)
Inserts the items in the specified collection into the list view at the
specified index.
| ||||||||||
void |
clear()
Removes all items from the list view.
| ||||||||||
E |
get(int index)
Gets the element at the specified index from the list view.
| ||||||||||
final View |
getEmptyView()
Gets teh
View that is displayed when there are no items in the
list. | ||||||||||
List<E> |
getList()
Gets the list of items that is managed by this list view.
| ||||||||||
final ListView<E> |
getListView()
Gets the ListView that holds all of the items on this screen.
| ||||||||||
E |
getSelectedItem()
Gets the currently selected item in the list view.
| ||||||||||
void |
refresh()
Refreshes the list view to update its contents from the list it manages.
| ||||||||||
E |
remove(int index)
Removes the item at the specified index from the list view.
| ||||||||||
boolean |
remove(E item)
Removes the specified item from the list view.
| ||||||||||
E |
set(int index, E item)
Replaces the element at the specified index from the list view with
another item.
| ||||||||||
void |
setEmptyMessage(String message)
Sets an informational message that will be displayed on the screen when the list is empty. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
afterLayoutInflated(boolean inflated)
This method is called after an attempted was made to inflate the
screen's layout.
| ||||||||||
TextView |
createEmptyView(ListScreen<E> parent)
This factory method is used to create the | ||||||||||
ListView<E> |
createListView(ListScreen<E> parent)
This factory method is used to create the ListView
that will be contained by this screen.
| ||||||||||
void |
onResume()
Overridden to refresh the list view whenever the screen is about to be
presented to the user, in case the underlying data model has changed due
to actions on another screen.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
sofia.app.Screen
| |||||||||||
From class
android.app.Activity
| |||||||||||
From class
android.view.ContextThemeWrapper
| |||||||||||
From class
android.content.ContextWrapper
| |||||||||||
From class
android.content.Context
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
android.content.ComponentCallbacks
| |||||||||||
From interface
android.view.KeyEvent.Callback
| |||||||||||
From interface
android.view.LayoutInflater.Factory
| |||||||||||
From interface
android.view.View.OnCreateContextMenuListener
| |||||||||||
From interface
android.view.Window.Callback
| |||||||||||
From interface
sofia.app.ScreenMethods
|
Adds an item to the list view.
item | the item to add to the list view |
---|
Inserts an item into the list view at the specified index.
index | the index where the new item should be inserted |
---|---|
item | the item to add to the list view |
Adds the items in the specified collection to the list view.
collection | the items to add to the list view |
---|
Inserts the items in the specified collection into the list view at the specified index.
index | the index where the new items should be inserted |
---|---|
collection | the items to add to the list view |
Removes all items from the list view.
Gets the element at the specified index from the list view.
index | the index of the item to retrieve |
---|
Gets the list of items that is managed by this list view. Changes made
to the structure of the list returned by this method (that is, adding,
removing, or replacing items) will be immediately reflected in the list
view. You only need to explicitly refresh()
the list if you
make a change to an element inside the list without directly modifying
the list itself.
List
of items managed by this list view
Gets the ListView that holds all of the items on this screen.
Gets the currently selected item in the list view.
Refreshes the list view to update its contents from the list it manages.
This method does not need to be called after methods like add
or remove
-- it only needs to be called if you change a property
of one of the elements in the list (for example, by calling a setter)
without modifying the structure of the list itself.
Removes the item at the specified index from the list view.
index | the index of the item to be removed |
---|
Removes the specified item from the list view.
item | the item to remove from the list view |
---|
Replaces the element at the specified index from the list view with another item.
index | the index of the item to retrieve |
---|---|
item | the item to put into the list |
Sets an informational message that will be displayed on the screen when the list is empty.
It is only appropriate to call this method if the empty view is a
TextView (or subclass of TextView
). If the view is any
other type, an exception will be thrown.
message | the list |
---|
IllegalStateException | if the empty view is not a
TextView (or subclass)
|
---|
This method is called after an attempted was made to inflate the
screen's layout. Most users will not need to call or override this
method; it is provided for Sofia's own subclasses of Screen
to
support custom behavior depending on whether a user layout was provided
or not.
This factory method is used to create the View
that will be
displayed when the list is empty. It is provided for subclass
extensibility, in case a subclass of ListScreen
wants to use a
more specialized view.
The default implementation of this method creates a TextView
with textAppearanceMedium
, text horizontally and vertically
centered, and a padding of 10 pixels.
parent | The screen that will contain the view (e.g., "this") |
---|
View
object to display when the list is empty.
This factory method is used to create the ListView
that will be contained by this screen. It is provided for
subclass extensibility, in case a subclass of ListScreen
wants
to use a more specialized ListView
instance.
parent | The screen that will contain the view (e.g., "this") |
---|
ListView
object to use for this screen.
Overridden to refresh the list view whenever the screen is about to be presented to the user, in case the underlying data model has changed due to actions on another screen.