Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

method does not override method from its superclass . Android Fragment

fragment1:

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

like image 430
pmipmi Avatar asked Feb 01 '15 11:02

pmipmi


People also ask

Which of the following can be inserted to override the superclass method?

Override a method of a superclass On the Code menu, click Override methods Ctrl+O . Alternatively, you can right-click anywhere in the class file, then click Generate Alt+Insert , and select Override methods.

What do you mean by overriding in Java?

In Java, method overriding occurs when a subclass (child class) has the same method as the parent class. In other words, method overriding occurs when a subclass provides a particular implementation of a method declared by one of its parent classes.


1 Answers

Spelling mistake. Name the method onCreateView instead of OnCreateView.

like image 91
Bubletan Avatar answered Oct 14 '22 03:10

Bubletan