2014-04-12 45 views
3

我今天在android studio遇到错误。我正在尝试在应用中创建一个关于我们的屏幕。布局xml文件已经创建。任何帮助表示赞赏。谢谢。android无法解析方法setcontentview

错误:无法解析方法的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); 
} 

} 
+2

使用onCreateView()在Fragmnets,的setContentView(R.layout.about_screen)的onCreateView膨胀about_screen.xml;在Activity中工作。 –

回答

9

你的类扩展Fragment,你有setContentView(R.layout.about_screen);setContentView是Activity类的一个方法。

代替在Fragment

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

工作。谢谢你们:) – kilomo

+1

很高兴帮助:) – Raghunandan