public class SortableTableView<T> extends TableView<T>
TableView
that gives the possibility to sort the table by every single
column. For this purpose implementations of Comparator
are used. If there is a comparator
set for a column the SortableTableView
will automatically display an ImageView at the start
of the header indicating to the user, that this column is sortable.
If the user clicks this header the given comparator will used to sort the table ascending by the
content of this column. If the user clicks this header again, the table is sorted descending
by the content of this column.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SAVED_STATE_SORTED_COLUMN |
static java.lang.String |
SAVED_STATE_SORTED_DIRECTION |
static java.lang.String |
SAVED_STATE_SUPER_STATE |
Constructor and Description |
---|
SortableTableView(Context context)
Creates a new SortableTableView with the given context.
|
SortableTableView(Context context,
AttributeSet attributes)
Creates a new SortableTableView with the given context.
|
SortableTableView(Context context,
AttributeSet attributes,
int styleAttributes)
Creates a new SortableTableView with the given context.
|
Modifier and Type | Method and Description |
---|---|
java.util.Comparator<T> |
getColumnComparator(int columnIndex)
Gives the
Comparator of the column at the given index. |
SortStateViewProvider |
getHeaderSortStateViewProvider()
Gives the current
SortStateViewProvider . |
protected void |
onRestoreInstanceState(Parcelable state) |
protected Parcelable |
onSaveInstanceState() |
void |
setColumnComparator(int columnIndex,
java.util.Comparator<T> columnComparator)
Sets the given
Comparator for the column at the given index. |
void |
setDataAdapter(TableDataAdapter<T> dataAdapter)
Sets the
TableDataAdapter that is used to render the data view for each cell. |
void |
setHeaderSortStateViewProvider(SortStateViewProvider provider)
Sets the given
SortStateViewProvider . |
void |
sort(java.util.Comparator<T> comparator)
Sorts the table using the given
Comparator . |
void |
sort(int columnIndex)
Sorts the table by the values of the column with the given index.
|
void |
sort(int columnIndex,
boolean sortAscending)
Sorts the table by the values of the column of the given index.
|
addDataClickListener, addDataLongClickListener, addHeaderClickListener, getColumnCount, getColumnWeight, getDataAdapter, getHeaderAdapter, isSwipeToRefreshEnabled, removeDataClickListener, removeDataLongClickListener, removeHeaderClickListener, removeHeaderListener, removeTableDataClickListener, setColumnCount, setColumnWeight, setDataRowBackgroundProvider, setDataRowColorizer, setHeaderAdapter, setHeaderBackground, setHeaderBackgroundColor, setHeaderElevation, setHeaderView, setSaveEnabled, setSwipeToRefreshEnabled, setSwipeToRefreshListener
public static final java.lang.String SAVED_STATE_SUPER_STATE
public static final java.lang.String SAVED_STATE_SORTED_DIRECTION
public static final java.lang.String SAVED_STATE_SORTED_COLUMN
public SortableTableView(Context context)
new SortableTableView(context, null, android.R.attr.listViewStyle
)context
- The context that shall be used.public SortableTableView(Context context, AttributeSet attributes)
new SortableTableView(context, attrs, android.R.attr.listViewStyle
)context
- The context that shall be used.attributes
- The attributes that shall be set to the view.public SortableTableView(Context context, AttributeSet attributes, int styleAttributes)
context
- The context that shall be used.attributes
- The attributes that shall be set to the view.styleAttributes
- The style attributes that shall be set to the view.public void setDataAdapter(TableDataAdapter<T> dataAdapter)
TableView
TableDataAdapter
that is used to render the data view for each cell.setDataAdapter
in class TableView<T>
dataAdapter
- The TableDataAdapter
that should be set.public void setColumnComparator(int columnIndex, java.util.Comparator<T> columnComparator)
Comparator
for the column at the given index. The comparator will be used for
sorting the given column.columnIndex
- The index of the column the given Comparator
shall be set to.columnComparator
- The Comparator
that shall be set to the column at the given index.public SortStateViewProvider getHeaderSortStateViewProvider()
SortStateViewProvider
.SortStateViewProvider
that is currently used to render the sort views in the header.public void setHeaderSortStateViewProvider(SortStateViewProvider provider)
SortStateViewProvider
.provider
- The SortStateViewProvider
that shall be used to render the sort views in the header.public java.util.Comparator<T> getColumnComparator(int columnIndex)
Comparator
of the column at the given index.columnIndex
- The index of the column to receive the applied Comparator
.Comparator
of the column at the given index.public void sort(int columnIndex)
sort(Comparator<T>
.columnIndex
- The index of the column on which the sorting shall be executed.public void sort(int columnIndex, boolean sortAscending)
columnIndex
- The index of the column for which the sorting shall be executed.sortAscending
- Indicates whether the table was sorted ascending TRUE
or descending FALSE
.public void sort(java.util.Comparator<T> comparator)
Comparator
.comparator
- The Comparator
that shall be used to sort the table.protected Parcelable onSaveInstanceState()
protected void onRestoreInstanceState(Parcelable state)