本文介绍了android无法解析方法setcontentview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我今天在android studio中遇到了一个错误.我正在尝试在应用程序中创建一个关于我们的屏幕.布局xml文件已创建.任何帮助表示赞赏.谢谢.
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.
错误:无法解析方法setcontentview(int)
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);
}
}
推荐答案
您的类扩展了 Fragment
,并且您具有 setContentView(R.layout.about_screen);
. setContentView
是Activity类的一种方法.
Your class extends Fragment
and you have setContentView(R.layout.about_screen);
. setContentView
is a method of Activity class.
而不是在 Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.about_screeen, container, false);
return rootView;
}
这篇关于android无法解析方法setcontentview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!