JennyToy
JennyToy

Reputation: 628

Override onTouchEvent in derived class

I have a view v2 that extends another view v1. The parent view v1 has an onTouchEvent, but I would like the child view v2 to not use the onTouchEvent.

I set in the child view onTouchEvent to

 @Override
    public boolean onTouchEvent(MotionEvent event) {

                return false;



    }

Now when I create an instance of v2 in an Activity like

public class MainActivity extends AppCompatActivity implements V2.OnClickListener {

...

 @Override
    public void onClick(View view) {
        Log.d("TAG","BLA");
    }
}

The onclick event is not fired. If I make V2 not extend V1 it is fired. What am I doing wrong or is this not possible?

Upvotes: 1

Views: 160

Answers (1)

Roman Samoilenko
Roman Samoilenko

Reputation: 936

You are just declining all touch events for this view. And the design in which child class doesn't want the parent's features is bad. Consider both V1 and V2 to inherit from View class or create base class for them.

Upvotes: 1

Related Questions