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
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.
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.
Spelling mistake. Name the method onCreateView instead of OnCreateView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With