We have discussed the DataSource in previous post, we will continue discussion on the DataGrid.column in this post. Just a re-cap, we have following codes in previous post. DataGrid.column is parameter to DataGrid.addColumnStyle() as shown below.
DataGrid.setNoDataText("No data available");
DataGrid.addColumnStyle(new cls_datagrid.column("Header 1", "header_5", 50));
DataGrid.addColumnStyle(new cls_datagrid.column("Header 2", "header_4", 80));
DataGrid.addColumnStyle(new cls_datagrid.column("Header 3", "header_3", 130));
DataGrid.addColumnStyle(new cls_datagrid.column("Header 4", "header_2", 120));
DataGrid.addColumnStyle(new cls_datagrid.column("Header 5", "header_1", 80));
DataGrid.addColumnStyle(new cls_datagrid.column("Header 6", "header_0", 140));
DataGrid.setDataSource(DataSource);
DataGrid.refresh();
DataGrid.column is a static class in DataGrid class. As you might notice, column is a very simple class with getter and setter methods.
public static class column{
private String strColumnName;
private String strFieldName;
private int intWidth;
private int intIndex;
public column(String DisplayName, String FieldName, int width)
{
strColumnName = DisplayName;
strFieldName = FieldName;
intWidth = width;
}
public void setIndex(int index)
{
intIndex = index;
}
public int getIndex()
{
return intIndex;
}
public String getColumnName()
{
return strColumnName;
}
public String getFieldName()
{
return strFieldName;
}
public int getWitdh()
{
return intWidth;
}
public void setWidth(int width){
intWidth = width;
}
}
Let's examine the class DataGrid, finally. :)
public class cls_datagrid extends LinearLayout{
private Context mContext;
private members_collection mc;
private String strNoDataText;
class members_collection{
public ArrayList<column> COLUMN_STYLE;
}
public static class column{
private String strColumnName;
private String strFieldName;
private int intWidth;
private int intIndex;
public column(String DisplayName, String FieldName, int width)
{
strColumnName = DisplayName;
strFieldName = FieldName;
intWidth = width;
}
public void setIndex(int index)
{
intIndex = index;
}
public int getIndex()
{
return intIndex;
}
public String getColumnName()
{
return strColumnName;
}
public String getFieldName()
{
return strFieldName;
}
public int getWitdh()
{
return intWidth;
}
public void setWidth(int width){
intWidth = width;
}
}
public cls_datagrid(Context context , AttributeSet attrs) throws Exception {
super(context, attrs);
setOrientation(VERTICAL);
mContext = context;
mc = new members_collection();
mc.COLUMN_STYLE = new ArrayList<column>();
}
public void addColumnStyle(column columnStyle)
{
mc.COLUMN_STYLE.add(columnStyle);
}
public void setNoDataText(String strText)
{
strNoDataText = strText;
}
}
Couple of things to note here.
- DataGrid extends LinearLayout
- member_collection class is just a placeholder to hold variables that to be shared amongst all the classes in the package.
- In the construction, we initialize the columns as an ArrayList and assign it to mc.COLUMN_STYLE
- function addColumnStyle(column) simply take DataGrid.column and put it in the ArrayList
- setNoDataText() is used to assign string value to display for an empty DataGrid
Next, DataGrid Part 4 - DataGrid Header
No comments:
Post a Comment