How to use more than one extends?

Asked

Viewed 1,531 times

1

When I create the project it comes like this

public class MainActivity extends AppCompatActivity{

would like to use more of a extends how to do ?

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.view.View;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity implements SimpleOnScaleGestureListener {
private ImageView imageView;
private float scale = 1f;

@Override
public boolean onScale(ScaleGestureDetector detector) {

    //Factor de zoom correspondente ao movimento feito
    float scaleFactor = detector.getScaleFactor();

    //Executa o zoom
    performZoom(scaleFactor);
    return true;
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    scaleGestureDetector = new ScaleGestureDetector(this,new MainActivity());
    view.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            v.performClick();
            //Chamar o onTouchEvent do nosso ScaleGestureDetector
            scaleGestureDetector.onTouchEvent(event);
            return true;
        }
    });
     }



private void performZoom(float scaleFactor) {
    scale *= scaleFactor;
    scale = Math.max(0.1f, Math.min(scale, 5.0f));
    imageView.setScaleX(scale);
    imageView.setScaleY(scale);
}

}

  • 2

    Why do you need it?

  • @extension because of this extends SimpleOnScaleGestureListener

  • @ramaral what’s wrong I’m not managing to implement

  • Implement the Listener interface and delegate the execution of methods to your implementation.

  • 1

    Simpleonscalegesturelistener is not a interface. Eliminate implements SimpleOnScaleGestureListener and declare a Inner class that extends of Simpleonscalegesturelistener that is to copy the class code Scalelistener of another answer into the Mainactivity

  • 6

    Related, maybe duplicated: http://answall.com/q/22718/101

  • @ramaral the view would be who in the code ?

  • Is the Imageview where the zoom will be applied.

  • @ramaral but this private ImageView imageView; ?

  • @ramaral went all right, but I wanted to ask a question, at the time you zoom in well zoomed in how to move the finger image to see the other part of the images ?

  • Yeah, then things get complicated! Look at this reply

Show 6 more comments

1 answer

3

Java does not support more than one "parent class", the closest you will get is to derive extends of a class and implement implements how many interfaces you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.