Question

[Solved] 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

Enquirer: pmipmi

||

Solution #1:

Spelling mistake. Name the method onCreateView instead of OnCreateView.

Respondent: pmipmi

Solution #2:

I am not familiar with the android sdk but I think you need something like this

Fragment frag1 = new fragment1(){
         @Override
         public void onClick(View view) {
              fTrans = getFragmentManager().beginTransaction();
              fTrans.replace(R.id.frameLayout2, frag1);
              fTrans.addToBackStack(null);
              fTrans.commit();
         }
 };
Respondent: Bubletan

Solution #3:

return your inflated view

public View onCreateView(.....) {
...
...

return InputFragmentView;
}

and change OnCreateView to onCreateView.
you can tap ctrl+o to get it ready ^^

Respondent: SteveL

Solution #4:

In my case I was not extending it from Fragment. Make sure you extend your fragment from Fragment class.

public class fragment1 extends Fragment implements View.OnClickListener {
   @Override
///   public View onCreateView.......
}
Respondent: B.Moataz

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy