Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android cannot resolve method setcontentview

I came across an error today in android studio. I am trying to create a about us screen in the app. The layout xml file has been created. Any help is appreciated. Thanks.

error: cannot resolve method setcontentview(int)

package example.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class AboutFragment extends android.app.Fragment {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_screen);
}

}
like image 203
kilomo Avatar asked Apr 12 '14 18:04

kilomo


1 Answers

Your class extends Fragment and you have setContentView(R.layout.about_screen);. setContentView is a method of Activity class.

Instead inflate about_screen.xml in onCreateView of Fragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.about_screeen, container, false);
    return rootView;
}
like image 140
Raghunandan Avatar answered Nov 20 '22 08:11

Raghunandan