DataGridView¶
-
public class
DataGridView
extends LinearLayout¶ DataGridView can be used to display a list or table of data records providing features like pagination.
Its takes a List of Maps that contains data and renders each row using a set of
ColumnInterface
presenting data in the form of a table.The minimal code needed to use DataGridView is as follows:
dataGridView = (DataGridView) findViewById(R.id.data_view); dataGridView.setPageSize(3); List data = "...; dataGridView.setData(data);
Its also possible to override which columns are used in the grid and customize those columns as one wishes.
Assuming in the data provided to the gridview looks like this
[{“first_name”:”jake”, “age”:”4”}, {“first_name”:”joan”, “age”:”6”}, ]
The ealier example will render both the firstname and age column on the grid we can tell the gridview to only render the firstname by
DataGridView.setColumns(Map)
as shown below:Map cols = new HashMap(); cols.put("first_name", new Column(this,"first_name","First Name")); dataGridView.setColumns(cols);
Fields¶
Constructors¶
Methods¶
addColumn¶
-
public void
addColumn
(BaseColumn col, boolean position)¶ Add extra columns to the dataview
Parameters: - col –
- position – true to add column at the beginning, false to add to the right
getColumns¶
-
public Map<String, ColumnInterface>
getColumns
()¶ Returns of columns to use on this grid.
Returns: grid columns.
getDataListener¶
-
protected DataListener
getDataListener
()¶
setColumns¶
-
public void
setColumns
(Map attributesLabel)¶ Determine how and which columns of your data will be displayed by passing them here.
This overrides the default implementation of using all the columns in you data.
this method accepts a map in the following form {“gender}
Parameters: - attributesLabel – a map
setData¶
setPaginator¶
-
public void
setPaginator
(PaginatorInterface paginator, LazyResolver lazyResolver)¶
setQuery¶
-
public void
setQuery
(SQLiteDatabase database, String sql, String[] params)¶ You can populate the datagrid using a query. THe data grid will fetch data in a paginated manner base on the page size set.
dataGridView = (DataGridView) findViewById(R.id.content_dsp); dataGridView.setPageSize(3); dataGridView.setQuery(SqlHelper.getInstance(this).getReadableDatabase(), "select * from coffees", new String[]{});
Parameters: - database – a SQLiteDatabase to use
- sql – querys to fetch data
- params – binding params to the query