Problem CalendarView in extends (navigation drawer) Fragment?

0

I'm trying to put a calendarview in a navigation drawer but it will not let me.

The Presentacion.java:

    implements NavigationView.OnNavigationItemSelectedListener,FragmentFirst.OnFragmentInteractionListener,
    FragmentSecond.OnFragmentInteractionListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@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();




    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    boolean FragmentTransaction = false;
    Fragment fragment = null;

    if (id == R.id.PRIMERO) {

            Intent siguiente = new Intent(this,PrimerCuatrimestre_1.class);
            startActivity(siguiente);

    } else if (id == R.id.SEGUNDO) {

        fragment = new FragmentSecond();
        FragmentTransaction = true;


    } else if (id == R.id.TERCERO) {

    } else if (id == R.id.CUARTO) {

    } else if (id == 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"));

    } else if (id == R.id.nav_puntuar) {

    }

    if(FragmentTransaction) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_main,fragment)
                .commit();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}

}

The content_main where the calendar goes:

<CalendarView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/calendarView"
    android:layout_below="@+id/date_display"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<TextView
    android:id="@+id/date_display"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Calendar View Date Display"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="55dp" />

I tried to put the following in the .java but it gives me a bug in lines when putting the code.

CalendarView calendarView;     TextView dateDisplay;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.android_calendar_view_example);

    calendarView = (CalendarView) findViewById(R.id.calendarView);
    dateDisplay = (TextView) findViewById(R.id.date_display);
    dateDisplay.setText("Date: ");

    calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
        @Override
        public void onSelectedDayChange(CalendarView calendarView, int i, int i1, int i2) {
            dateDisplay.setText("Date: " + i2 + " / " + i1 + " / " + i);

            Toast.makeText(getApplicationContext(), "Selected Date:\n" + "Day = " + i2 + "\n" + "Month = " + i1 + "\n" + "Year = " + i, Toast.LENGTH_LONG).show();
        }
    });
    
asked by Rf Mvs 12.08.2016 в 16:16
source

0 answers