- basic style without color pattern
- With color pattern and with vertical diviser only
- With color pattern and with horizontal diviser only
Integrate the DataGridVlew module into your project
include the namespace in your xml layout file :
xmlns:app="http://schemas.android.com/apk/res-auto"
<jkas.datagridview.DataGridView
android:id="@+id/data_grid_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:diviserSize="2dp"
app:diviserColor="@color/backgroundColorHeader"
app:diviserHeaderColor="@android:color/transparent"
app:columnCount="5"
app:columnHeaderTextColor="@color/textColorHeader"
app:columnHeaderBackgroundColor="@color/backgroundColorHeader"
app:columnHeaderHeight="43dp"
app:showVerticalSeparator="true"
app:showHorizontalSeparator="true"
app:rowHeight="30dp"
app:rowTextColor="@color/textColorRow"
app:rowBackgroundColor="@color/backgroundColorRow" />
- To add data to the grid, you need to create an object of type
Row
from the DataGridView. from this new object created (Row
), you would add new cells that will represent the data of the column. the objectCell
can only be created from the line (object)Row
that was created (rowObject.newCell()
)
java
DataGridView dataGV = binding.dataGridView; // get the DataGridVlew view via findViewById or DataBinding
Row row = dataGV.newRow(); // create the new row from the DataGridVlew.
// adding Cell in Row object
row.addCell(row.newCell().setTextContent("data cell 1"));
row.addCell(row.newCell().setTextContent("data cell 2"));
row.addCell(row.newCell().setTextContent("data cell 3"));
row.addCell(row.newCell().setTextContent("data cell 4"));
row.addCell(row.newCell().setTextContent("data cell 5"));
// adding Row line in DataGridVlew.
dataGV.addRow(row);
kotlin
val dataGV = binding.dataGridView //get the DataGridVlew view via findViewById or DataBinding.
val row = dataGV.newRow() // creating the record row (Row)
row.addCell(row.newCell().setTextContent("data cell 1"))
row.addCell(row.newCell().setTextContent("data cell 2"))
row.addCell(row.newCell().setTextContent("data cell 3"))
row.addCell(row.newCell().setTextContent("data cell 4"))
row.addCell(row.newCell().setTextContent("data cell 5"))
// adding Row line in DataGridVlew.
dataGV.addRow(row)
- By default for all
Cell
s, the default generated view will be theTextView
. you can also customize your own views which are embedded in theCell
s.
java
View myCustomView = ...; // The view you prefer to use instead of the one that will be created by default.
Row row = dataGV.newRow();
Row.Cell cell = row.newCell();
cell.setView(myCustomView);
row.addCell(cell);
kotlin
val myCustomView = ... // The view you prefer to use instead of the one that will be created by default.
val row = dataGV.newRow()
val cell = row.newCell()
cell.setView(myCustomView)
row.addCell(cell)
- Creating the grid header always follows the same procedure which consists of creating a
Row
either via thenewRow()
method .
java
Row rowHeader = dataGV.newRow();
rowHeader.addCell(...); // adding all necessary cells.
// set or update header
dataGV.setHeader(rowHeader);
kotlin
val rowHeader = dataGV.newRow()
rowHeader.addCell(...) // adding all necessary cells.
// set or update header
dataGV.setHeader(rowHeader)
- For setting up color patterns (as in screenshots) it's pretty simple. you just need to get the object keeps the default settings of the DataGridView and change its values
DefaultSetting
.
java
DataGridVlew.DefaultSetting setting = dataGV.getDefaultSetting(); // getting the DefaultSetting object.
setting.usePattern = true;
// for columns only.
setting.addColorInListColumn(Color.RED);
setting.addColorInListColumn(Color.GREEN);
// for rows only
setting.addColorInListRow(Color.RED);
setting.addColorInListRow(Color.GREEN);
//...
kotlin
val setting = dataGV.getDefaultSetting() // getting the DefaultSetting object.
setting.usePattern = true
// for columns only.
setting.addColorInListColumn(Color.RED)
setting.addColorInListColumn(Color.GREEN)
// for rows only
setting.addColorInListRow(Color.RED)
setting.addColorInListRow(Color.GREEN)
//...
If you want to use this multiple coloring of columns and/or rows, let the value of usePattern
be true
XML Attributs | Code Method | Description |
---|---|---|
app:diviserSize |
setDiviserSize(int size) |
the size of the column and row divider |
app:diviserColor |
setDiviserColor(int color) |
The colors of the loaded data grid dividers |
app:diviserHeaderColor |
setDiviserHeaderColor(int color) |
The color of the grid header dividers. |
app:columnCount |
setColumnCount(int counter) |
The maximum number of columns allowed |
app:columnHeaderTextColor |
setColumnHeaderTextColor(int color) |
The header text color |
app:columnHeaderBackgroundColor |
setColumnHeaderBackgroundColor(int color) |
The header background color |
app:columnHeaderHeight |
setColumnHeaderHeight(float dimen) |
the height size of the header |
app:showVerticalSeparator |
showVerticalSeparator(boolean show) |
Show vertical divider |
app:showHorizontalSeparator |
showHorizontalSeparator(boolean show) |
Show horizontal divider |
app:rowHeight |
setRowHeight(float dimen) |
the height size of the row |
app:rowTextColor |
setRowTextColor(int color) |
The row text color |
app:rowBackgroundColor |
setRowBackgroundColor(int color) |
The row background color |
It is important to know this before loading data into the grid :
- set
columnCount
before data loading, Otherwise an exception will be thrown. - the number of
Cell
s added must be equal tocolumnCount
otherwise an exception will be thrown if the number ofCell
s is greater than the limitcolumnCount
. - if the number of
Cell
s is less thancolumnCount
,Cell
s will be added with default values(none)
to fill the gaps.
- Telegram: https://t.me/jkas_dbt
- Gmail : jkas.dbt@gmail.com
- Rosette Bikangu for Support
- Andi Hasan A
- Akash Yadav for creating AndroidIDE