2014-04-12 42 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