【问题标题】:android cannot resolve method setcontentviewandroid无法解析方法setcontentview
【发布时间】:2014-04-12 18:18:47
【问题描述】:

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

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

}

【问题讨论】:

  • 在 Fragmnets 中使用 onCreateView(), setContentView(R.layout.about_screen);在 Activity 中工作。

标签: android android-fragments


【解决方案1】:

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

而是将about_screen.xml 膨胀到onCreateViewFragment

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

【讨论】:

    猜你喜欢
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多