I am trying to add to the navigation drawer using fragments as follows using the onNavigationDrawerItemSelected But the compiler is giving me a incomparable type I do not no how I am new to Andriod I used the NaviagationDrwaer Template app to give me heads start.

I am hopeing someone can point me in the right direction with this been driving me nuts. Also any ideas with this apporach how one would handle icons in the menu ?.

 public void onNavigationDrawerItemSelected(int position) {

    Fragment fragment;

        case 0:
            fragment = new  HomeFragment();  --- This line is where the error comes


    // update the main content by replacing fragments
    FragmentManager fragmentManager = getSupportFragmentManager()
            .replace(R.id.container, fragment)


My HomeFragment Class Conists Of

public class HomeFragment extends  Fragment  {
    View rootview;
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootview = inflater.inflate(R.layout.home_layout, container, false);
        return rootview;

And my home_layout file as follows

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.example.davidbuckley.cautioapp.home">

<!-- TODO: Update blank fragment layout -->
<TextView android:layout_width="match_parent" android:layout_height="match_parent"
    android:text="@string/hello_blank_fragment" />


Related posts

Recent Viewed