El problema es que tengo un Fragment y no funciona... :
He probado esto pero no funciona :
public class FragmentoPerfil extends Fragment {
CalendarView calendar;
public FragmentoPerfil() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
calendar = (CalendarView) getActivity().findViewById(R.id.calendarView);
calendar.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
// display the selected date by using a toast
Toast.makeText(getActivity().getApplicationContext(), dayOfMonth + "/" + month + "/" + year, Toast.LENGTH_LONG).show();
}
});
return inflater.inflate(R.layout.fragmento_perfil, container, false);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dee4ee"
android:orientation="vertical"
android:padding="@dimen/espacio_norma_1"
android:weightSum="1">
<CalendarView
android:layout_width="match_parent"
android:layout_height="371dp"
android:id="@+id/calendarView"
android:layout_weight="0.40" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/float_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</LinearLayout>
Parte donde llamo a los Fragment en el MainActivity:
private void seleccionarItem (MenuItem itemDrawer)
{
Fragment fragmentoGenerico = null;
FragmentManager fragmentManager = getSupportFragmentManager();
switch (itemDrawer.getItemId()) {
case R.id.CALENDARIO:
fragmentoGenerico = new FragmentoPerfil();
break;
case R.id.PRIMERO:
fragmentoGenerico = new FragmentPrimero();
break;
case R.id.SEGUNDO:
fragmentoGenerico = new FragmentSegundo();
break;
case R.id.TERCERO:
fragmentoGenerico = new FragmentTercero();
break;
case R.id.CUARTO:
fragmentoGenerico = new FragmentCuarto();
break;
case R.id.nav_share:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "AndroidSolved");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "si que funciona");
startActivity(Intent.createChooser(sharingIntent, "Share via"));
break;
}