mardi 5 mai 2015

Intent not working in NavigationDrawerFragment

I'm trying to call another activity using my NavigationDrawerFragment. Under my onOptionsItemSelected I create an intent and call the said intent but for some reason it is showing up as an error.

Intent intent = new Intent(this, HomeActivity.class);

I was wondering why it was not working since :

  • I already have a HomeActivity class

  • I also have added it in the manifest

  • Other activities are also calling the HomeActivity class and it seems to be working just fine.

    @Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }

        if (item.getItemId() == R.id.action_example) {
            Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT)
                    .show();
    
    
           int pos = 1;
           switch(pos){
    
           case 1:
               Intent intent = new Intent(this, HomeActivity.class);
                this.startActivity(intent);
                break;  
    
           }
    
            return true;
        }
    
        return super.onOptionsItemSelected(item);
    }
    
    

Am I doing something wrong in my code which is why it is showing up as an error? Update:

The error message is this:

The constructor Intent(NavigationDrawerFragment, Class) is undefined

Aucun commentaire:

Enregistrer un commentaire