display only as many days as there are in the current month

This commit is contained in:
tibbi 2016-01-27 18:54:10 +01:00
parent 6e4d4a4f7e
commit 883f30e361
1 changed files with 10 additions and 1 deletions

View File

@ -7,6 +7,8 @@ import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import org.joda.time.DateTime;
public class MainActivity extends AppCompatActivity {
@Override
@ -17,11 +19,18 @@ public class MainActivity extends AppCompatActivity {
TableLayout tableHolder = (TableLayout) findViewById(R.id.table_holder);
LayoutInflater inflater = getLayoutInflater();
DateTime dateTime = new DateTime();
final int currMonthDays = dateTime.dayOfMonth().getMaximumValue();
for (int i = 0; i < 5; i++) {
final TableRow row = (TableRow) inflater.inflate(R.layout.table_row, tableHolder, false);
for (int j = 1; j < 8; j++) {
final int currDate = i * 7 + j;
if (currDate > currMonthDays)
break;
final TextView day = (TextView) inflater.inflate(R.layout.table_day, row, false);
day.setText("" + (i * 7 + j));
day.setText(String.valueOf(currDate));
row.addView(day);
}