How to setContentView in a fragment?

You dont call setContentView in fragments, in fact you need to return a View from onCreateView.

Try replacing:

setContentView(new SampleView(this));

With this:

return new SampleView(this);

Return the view instance you want to use:

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

Also it's not safe to call getActivity() from onCreateView(). Make sure you call it in or after onActivityCreated(), as at this point your Fragment is fully associated with the Activity. Check Fragment's lifecycle.

Fragments