How to
create lines in a spreadsheet in Android?
Creating a
spreadsheet in Android simply does not draw borders.
Tables in
Android:
Tables in
Android consist of a TableLayout and TableRows. All cells are designed by the
interior layout design.
In this
code example, frames are created around the rows of tables.
Solution:
Create
frames around cells and rows by loading a drawable-character element in the
background.
drawable
Under app /
res / drawable you create a new drawable file and create an android: shape of
the type: Rectangle.
At runtime,
this background is then programmatically loaded into the table row or into view
elements and cells.
<?xml version="1.0"
encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle">
<padding
android:bottom="0dp"
android:top="0dp"
></padding>
<stroke android:width="1px"
android:color="#000000"/>
</shape>
|
Android Java
Runtime
code, programmed
App / java
/ project, package / CalendarActivity, Activity
The
background drawing object is loaded with row.setBackground (Drawable) at
runtime
//--< Row >--
TableRow row = new TableRow(this);
//< set Border >
row.setBackground(ContextCompat.getDrawable(context, R.drawable.border));
//*not:
TableRow.LayoutParams lp=new
TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT);
//*not: row.setPadding(1,1,1,1);
//</ set Border >
|
reference
Complete
Android Java code for spreadsheet
TableLayout tbl = new TableLayout(this);
tbl.setMinimumWidth(300);
//tbl.setBackgroundResource(R.drawable.rectangle);
//</ Header >
//----< @Loop: Days >----
for (int iDay = 1; iDay <= 31; iDay++) {
//----< Day-Row >----
//-< Date >-
Date dtRow = clsDate.getDate_by_Year_Month_Day(Calendar_Year,
Calendar_Month, iDay);
//< weekday >
//*as string
SimpleDateFormat fmtWeekday = new SimpleDateFormat("EE");
String weekday =
fmtWeekday.format(dtRow);
//</ weekday >
//*as weekday_number
Calendar calendarDay = Calendar.getInstance();
calendarDay.setTime(dtRow);
int NrWeekday =
calendarDay.get(Calendar.DAY_OF_WEEK);// fmtWeekdayNr.format(dtRow);
//-</ Date >-
//--< Row >--
TableRow row = new TableRow(this);
//< set Border >
row.setBackground(ContextCompat.getDrawable(context, R.drawable.border));
//not: TableRow.LayoutParams lp=new
TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT);
//not: row.setPadding(1,1,1,1);
//</ set Border >
if (NrWeekday == Calendar.SATURDAY || NrWeekday == Calendar.SUNDAY) {
row.setBackgroundColor(Color.rgb(200, 200, 200));
}
if (dtRow.equals(_dtToday)) {
row.setBackgroundColor(Color.rgb(200, 0, 0));
}
//< dayNr >
TextView lblDayNr = new TextView(this);
lblDayNr.setText(String.valueOf(iDay)); //*cast integer to string
row.addView(lblDayNr);
//</ dayNr >
//--< weekday >--
TextView lblWeekday = new TextView(this);
lblWeekday.setText(weekday);
row.addView(lblWeekday);
//--</ weekday >--
row.setOnClickListener(on_Day_Row_Clicked);
//< set_keyTag >
String sDateRow = clsDate.format_to_ShortDate(dtRow);
row.setTag("row_" + sDateRow);
//</ set_keyTag >
//--</ Row >--
//< add to table >
tbl.addView(row);
//</ add to table >
//----</ Day-Row >----
}
|
Subject: TableRow row, cell?