Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve method getActivity()

  • I am new to Android and learning to create fragments in Android by following this
    example: Fragment Navigation Drawer

  • The code between Navigating between Menu Items and Add Navigation Header consists a method getActivity().

  • As the author didn't mentioned where to paste this code, I pasted in my MainActivity.java file

  • Is code between Navigating between Menu Items and Add Navigation Header pasted at correct location by me?

  • In method selectDrawerItem(MenuItem menuItem) there is a comment // Create a new fragment and specify the planet to show based on position
    Does author expects me to add something over here.

  • The project files layout created by me on AndroidStudio is as follow:AndroidStudio Snapshot
like image 241
Akki Avatar asked Sep 11 '15 15:09

Akki


1 Answers

You can use:

this Or `MainActivity.this` 

Instead of:

getActivity() 
like image 190
zohreh Avatar answered Oct 08 '22 11:10

zohreh