title: Android - GregorianCalendar determine if a day belongs to the current month
body: <p>I am making a calendar using a GridView and a custom BaseAdapter. I use a GregorianCalendar in a function to generate a string array of days in order to populate the cells. Here is the my MainActivity which handles the layout of the Calendar:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      private GridView calendarView, daysView;
      private final String[] weekdays = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat","Sun"};
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          daysView = (GridView) this.findViewById(R.id.daysGridView);
          daysView.setAdapter(new WeekDayGridAdapter(MainActivity.this, weekdays));
  
          calendarView = (GridView) this.findViewById(R.id.calendarGridView);
          calendarView.setAdapter(new DayGridAdapter(MainActivity.this, getMonth()));
      }
  
      private String[] getMonth(){
  
          int gridSizeX = 7, gridSizeY = 6;
          int gridsize = gridSizeX * gridSizeY;
          String[] myStringArray = new String[gridSizeX*gridSizeY];
  
          final Calendar calendar = Calendar.getInstance();
          int year = calendar.get(Calendar.YEAR);
          int month = calendar.get(Calendar.MONTH);
  
          GregorianCalendar gregorianCalendar = new GregorianCalendar(year, month, 1);
          //this gets the day of week range 1-7, Monday - Sunday
          int dayOfWeek = gregorianCalendar.get(Calendar.DAY_OF_WEEK);
          //backtracks to the beginning of current week (Monday)
          gregorianCalendar.add(Calendar.DAY_OF_YEAR, Calendar.MONDAY - dayOfWeek);
  
          for (int i = 0; i &lt; gridsize; i++)
              {
                  myStringArray[i] = String.valueOf(gregorianCalendar.get(Calendar.DAY_OF_MONTH));
                  gregorianCalendar.add(Calendar.DAY_OF_YEAR, 1);
              }
          return myStringArray;
      }
  }
  </code></pre>
  
  <p>And here is how my Calendar looks:
  <img src="https://i.stack.imgur.com/N3B4Y.jpg" alt="November 2013"></p>
  
  <p>What i want is a way to determine which cells belong to the previous or the next month relative to the current month. In the case of the image above that cells will be:</p>
  
  <ul>
  <li>the first 4</li>
  <li>the last 9</li>
  </ul>