java.lang.Object | |||
↳ | com.neomades.ui.View | ||
↳ | com.neomades.ui.AbsListView | ||
↳ | com.neomades.ui.ListView |
A ListView
is a vertical list of views, where only one view can
be clicked at the same time.
Each view can be different.
ItemSelectedListener listViewListener = new ItemSelectedListener() { public void onItemSelected(int index, String item) { // do some stuff } } ListView list = new ListView(); // add items here list.setItemSelectedListener(listViewListener);
In order to improve Long lists performance, prefer using ListAdapter
.
A ListAdapter
enable recycling item's view. Every time ListView needs
to show a new item , it will call the
getView()
method from its
adapter.
getView()
takes three arguments
arguments: the item position, a convertView, and the parent ViewGroup.
public View getView(int position, View convertView, View parent) { if (convertView == null) { // build a new item convertView = View.inflateXML(Res.layout.your_layout); } // update the convertView // Warning: findView could damage performances (see ViewHolder pattern // chapter) TextLabel text = (TextLabel) convertView.findView(Res.id.your_textLabel); text.setText("Position " + position); return convertView; }
public View getView(int position, View convertView, View parent) { ViewHolder holder; if (convertView == null) { // build a new item convertView = View.inflateXML(Res.layout.your_layout); holder = new ViewHolder(); // Because findView may have poor performances // It will done only once in the view build step // and saved inside ViewHolder for the next use holder.textLabel = (TextLabel) convertView.findView(Res.id.your_textLabel); convertView.setTag(holder); } // update the convertView holder = (ViewHolder) convertView.getTag(); holder.textLabel.setText("Position " + position); return convertView; }
Avoid setting MATCH_CONTENT
for ListViews
or ScrollViews at all times. The hierarchy of ListView is also concerned by
this note. MATCH_CONTENT
in the hierarchy
could break down the ListView
display.
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Attribute Name | Related Method | Description | |||||||||
listIndicatorVisible | setListIndicatorVisible(boolean) |
[Expand]
Inherited XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | STYLE_GROUPED | A ListView whose sections present distinct groups of rows. | |||||||||
int | STYLE_PLAIN | A plain ListView. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ListView()
Creates a new list view.
| |||||||||||
ListView(int style)
Sets the iOS UITableView style.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
scrollToPosition(int itemPosition)
Set the scrolled position of your ListView.
| ||||||||||
void |
scrollToTop()
Move the scroll position to the first item of your
ListView . | ||||||||||
void |
setListIndicatorVisible(boolean indicatorVisible)
Displays or hide the list indicator (generally something that represents an
arrow at the tight of the ListView cell).
| ||||||||||
void |
setPullToRefreshListener(PullToRefreshListener listener)
Sets a pull-to-refresh listener to the
ListView . | ||||||||||
void |
setPullToRefreshText(String text)
If a
PullToRefreshListener is set, this text will be displayed at the
top of the list when the user is pulling downward but not enough to trigger
the pull-to-refresh event. | ||||||||||
void |
setRefreshComplete()
If a
PullToRefreshListener is set, notifies the ListView
that the refresh is over. | ||||||||||
void |
setRefreshLoadingText(String text)
If a
PullToRefreshListener is set, this text will be displayed at the
top of the list when a pull-to-refresh event occurred. | ||||||||||
void |
setReleaseToRefreshText(String text)
If a
PullToRefreshListener is set, this text will be displayed at the
top of the list when the user has enough pulled downward. | ||||||||||
void |
setRowHeightAdapter(RowHeightAdapter rowHeightAdapter)
Sets an adapter for row heights.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() |
A ListView whose sections present distinct groups of rows. The section headers and footers do not float.
A plain ListView. Any section headers or footers are displayed as inline separators and float when the ListView is scrolled.
Creates a new list view.
Sets the iOS UITableView style. (Only for iOS)
style | STYLE_PLAIN (default) or STYLE_GROUPED |
---|
Set the scrolled position of your ListView.
If the position is higher than the item count, the ListView
is
scrolled to the last item.
If the position is less than 0, the ListView
is scrolled to the first
item.
On Android
, ListView
will scroll to the item position
only if it is not already locate in the visible area.
If the item is below the visible area, it will move to the bottom of the
ListView.
If the item is above the visible area, it will move to the top of the
ListView.
itemPosition | the item position to scroll to |
---|
Displays or hide the list indicator (generally something that represents an arrow at the tight of the ListView cell).
indicatorVisible | true to display the indicator |
---|
Sets a pull-to-refresh listener to the ListView
. To have more
precision about the pull-to-refresh mechanism, see
PullToRefreshListener
.
To properly configure a pull-to-refresh on the ListView
, text in
the header of the list can be configured. These texts will be shown in the
upper part of the list when the user over-scrolls it.
setPullToRefreshText(String)
: the user is pulling downward the
list but it is not enough yet to trigger the refresh.setReleaseToRefreshText(String)
: the list was enough pulled,
indicates to the user that he can release the list to trigger the refresh.
setRefreshLoadingText(String)
: the list is refreshing.
Do not forget to call setRefreshComplete()
in the pull-to-refresh
callback to indicate to the list that the refresh is over.
Should be called before setListAdapter(ListAdapter)
and
related methods.
listener | non-null listener will enabled pull to refresh mode |
---|
If a PullToRefreshListener
is set, this text will be displayed at the
top of the list when the user is pulling downward but not enough to trigger
the pull-to-refresh event.
This method has effect only in Android
and iOS
platforms.
text | the text that will be displayed at the top of the list |
---|
If a PullToRefreshListener
is set, notifies the ListView
that the refresh is over. This will hide the refresh text.
Should be called at the end of
onRefresh
method.
If a PullToRefreshListener
is set, this text will be displayed at the
top of the list when a pull-to-refresh event occurred. It may indicate to the
user that the list is refreshing.
This method has effect only in Android
and iOS
platforms.
text | the text that will be displayed at the top of the list |
---|
If a PullToRefreshListener
is set, this text will be displayed at the
top of the list when the user has enough pulled downward. It may indicate to
the user that he can release the list to trigger the refresh.
This method has effect only in Android
and iOS
platforms.
text | the text that will be displayed at the top of the list |
---|
Sets an adapter for row heights.
The adapter gives an height for each row (could be different).
rowHeightAdapter | an adapter or null |
---|