-2

Is there any way to replace the main layout in the navigation drawer with the Activity which extends AppCombatActivity not the Fragment.

Because whenever I do so it gives me the error that : Wrong 2nd argument type. Found:'myapp.hp.com.drawerdemo1.Main2Activity', required:'android.support.v4.app.Fragment' replace(int,android.support.v4.app.Fragment)in FragmentTransaction cannot be applied to(int,myapp.hp.com.drawerdemo1.Main2Activity)

I was doing this :

    if (id == R.id.nav_start) {
        // Handle the camera action
        getSupportActionBar().setTitle(name);
        Main2Activity main = new Main2Activity();
        android.support.v4.app.FragmentTransaction fragmentTransaction =
                getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.Fragment_Layout, main);
        fragmentTransaction.commit();
    }

Point to be noted : I don't need intent activity as it opens up the activity in the other layout which doesn't look much interactive.

What is the reason I want the activity layout instead of fragment layout :

  • In the class which extends Fragment its hard to perform and handle different action like button click and so on.
  • Difficult to initialize different events.
  • Main reason is that I'm naive at handling Fragments.

Please help as I need it. I'll appreciate if you will look forward to this problem and give me a solution. Thank You..:)

Alok
  • 8,452
  • 13
  • 55
  • 93

1 Answers1

0

In a fragment transaction you have to provide a fragment, that's just kind of self-evident.

In the class which extends Fragment its hard to perform and handle different action like button click and so on.

How so? Handling click events in a fragment and activity are done exactly the same way

Difficult to initialize different events.

How so?

Main reason is that I'm naive at handling Fragments.

Would recommend learning about them as it is impossible to progress much in Android development without being well-versed in fragments and how they are used.

Greg Ennis
  • 14,917
  • 2
  • 69
  • 74