androidandroid-fragmentsfloating-action-buttonappcompatactivity

Implementing Floating Action Button on a Fragment Class


Hi I want to add Floating Action Button on a Fragment Class, but when ever I add implements AppCompatActivity I get this error:

"getLoaderManager()' in 'android.support.v4.app.Fragment' clashes with 'getLoaderManager()' in 'android.app.Activity'; attempting to use incompatible return type"

public class home extends Fragment implements AppCompatActivity{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.home, container, false);
    return rootView;

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

}

}


Solution

  • Just remove "implements AppCompatActivity" from the fragment and add "extends AppCompatActivity" into the activity which holds the fragment.