Java 方法不会覆盖其超类中的方法。安卓片段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28262036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
method does not override method from its superclass . Android Fragment
提问by pmipmi
fragment1:
片段1:
public class fragment1 extends Fragment implements View.OnClickListener {
ImageButton but, but1, but2;
ImageView view;
@Override << this one
public View OnCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myView = inflater.inflate(R.layout.fragment1, null);
but = (ImageButton) myView.findViewById(R.id.imageButton11);
but.setOnClickListener(this);
but1 = (ImageButton) myView.findViewById(R.id.imageButton1);
but1.setOnClickListener(this);
but2 = (ImageButton) myView.findViewById(R.id.imageButton2);
but2.setOnClickListener(this);
return myView;
}
@Override
public void onClick(View v) {
main xxx = (main)getActivity();
switch (v.getId()) {
case R.id.imageButton11:
xxx.str="but1";
break;
..
}}
main:
主要的:
Fragment frag1 = new fragment1();
fr1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
fTrans = getFragmentManager().beginTransaction();
fTrans.replace(R.id.frameLayout2, frag1);
fTrans.addToBackStack(null);
fTrans.commit();
}
});
method does not override method from its superclass in fragment1(first override) but without "implemets View.OnClickListener" it works
方法不会在fragment1(第一次覆盖)中覆盖其超类中的方法,但没有“实现View.OnClickListener”它可以工作
采纳答案by Bubletan
Spelling mistake. Name the method onCreateView
instead of OnCreateView
.
拼写错误。命名方法onCreateView
而不是OnCreateView
.
回答by SteveL
I am not familiar with the android sdk but I think you need something like this
我对 android sdk 不熟悉,但我认为你需要这样的东西
Fragment frag1 = new fragment1(){
@Override
public void onClick(View view) {
fTrans = getFragmentManager().beginTransaction();
fTrans.replace(R.id.frameLayout2, frag1);
fTrans.addToBackStack(null);
fTrans.commit();
}
};
回答by B.Moataz
return your inflated view
返回你膨胀的视图
public View onCreateView(.....) {
...
...
return InputFragmentView;
}
and change OnCreateView to onCreateView. you can tap ctrl+o to get it ready ^^
并将 OnCreateView 更改为 onCreateView。你可以点击 ctrl+o 来准备它^^
回答by Ramesh Pareek
In my case I was not extending it from Fragment. Make sure you extend your fragment from Fragment
class.
就我而言,我不是从 Fragment 扩展它。确保你从Fragment
类中扩展你的片段。
public class fragment1 extends Fragment implements View.OnClickListener {
@Override
/// public View onCreateView.......
}