@Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments if (position != currPosition) { FragmentManager fragmentManager = getFragmentManager(); switch (position) { case 0: browsingFragment = BrowsingFragment.newInstance(dateString); fragmentManager.beginTransaction().replace(R.id.container, browsingFragment).commit(); currPosition = position; break; case 1: Intent i = new Intent(this, SettingsActivity.class); startActivity(i); break; } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); switch (id) { case R.id.action_refresh: browsingFragment.refresh(getApplicationContext()); break; case R.id.action_pick_day: // DialogFragment newFragment = new DatePickerFragment(); // newFragment.show(getFragmentManager(), "datePicker"); View view = getLayoutInflater().inflate(R.layout.calendar_date_picker, null); final CalendarPickerView calendarPickerView = (CalendarPickerView) view.findViewById(R.id.calendar); final Date today = new Date(); Calendar tmo = Calendar.getInstance(); tmo.add(Calendar.DAY_OF_MONTH, 1); Calendar janFirst = Calendar.getInstance(); janFirst.set(Calendar.MONTH, Calendar.JANUARY); janFirst.set(Calendar.DAY_OF_MONTH, 1); janFirst.set(Calendar.YEAR, 2014); calendarPickerView.init(janFirst.getTime(), tmo.getTime()).withSelectedDate(currDate); // Build the dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(view); // Set the view of the dialog to your custom layout builder.setTitle("View Products posted on..."); builder.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date selected = calendarPickerView.getSelectedDate(); Calendar calendar = Calendar.getInstance(); calendar.setTime(selected); Calendar current = Calendar.getInstance(); current.setTime(currDate); if (calendar.get(Calendar.MONTH) == current.get(Calendar.MONTH) && calendar.get(Calendar.DAY_OF_MONTH) == current.get(Calendar.DAY_OF_MONTH) && calendar.get(Calendar.YEAR) == current.get(Calendar.YEAR)) { dialog.dismiss(); return; } currDate = selected; String dateString = format.format(selected); browsingFragment.dateString = dateString; MainActivity.this.dateString = dateString; browsingFragment.refresh(getApplicationContext()); if (today.equals(selected)) { getActionBar().setTitle("Today's Hunts"); } else { getActionBar() .setTitle( "Hunts for " + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DAY_OF_MONTH)); } dialog.dismiss(); } }); // Create and show the dialog builder.create().show(); break; } return super.onOptionsItemSelected(item); }