[英]Method does not override method from its superclass
Can anyone tell me, why this error is displayed (or even have a better solution)? 谁能告诉我,为什么显示此错误(甚至有更好的解决方案)?
I'm new to Java (and Android) development, so I realy don't know my fault My Code: 我是Java(和Android)开发的新手,所以我真的不知道我的错我的代码:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class select_type extends Fragment {
public select_type() {
// Required empty public constructor
}
@Override //<--- Cause the ERROR
public View onCreateView(View view, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
return inflater.inflate(R.layout.fragment_select_type, container, false);
Button btn = (Button) view.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
noVIP TextFragment = new noVIP();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, TextFragment);
transaction.addToBackStack(null);
transaction.commit();
}
});
return view;
}
}
Replace: 更换:
public View onCreateView(View view, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
with: 有:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
as onCreateView()
is not passed a View
parameter . 因为
onCreateView()
没有传递View
参数 。
Also, get rid of super.onViewCreated(view, savedInstanceState);
此外,摆脱
super.onViewCreated(view, savedInstanceState);
. 。 It is neither necessary nor appropriate to be calling that where you are.
称您身在何处既没有必要,也不适当。
Please note that everything after your return
statement in that method will not be executed, since you are returning first. 请注意,该方法中
return
语句之后的所有内容都不会执行,因为您首先要返回。 Assign the inflater.inflate(...)
result to a local variable, use it, then return that variable at the end of your method. 将
inflater.inflate(...)
结果分配给局部变量,使用它,然后在方法末尾返回该变量。
You can override two methods also: 您还可以覆盖两个方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_select_type, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Button btn = (Button) view.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
noVIP TextFragment = new noVIP();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, TextFragment);
transaction.addToBackStack(null);
transaction.commit();
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.