SunSpike
SunSpike

Reputation: 127

How to detect touch event at ScrollView?

Before explaining, I don't want to use TouchEvent at Scrollview inner Scrollview.

I want to make when touching up the scrollView, make popup window. but to use onTouchEvent, isn't it only can detect ACTION_MOVE, UP, DOWN?

I used gesture detector.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read);

        ScrollView readScroll = (ScrollView)findViewById(R.id.readScrollView);
        TextView textView = (TextView)findViewById(R.id.TextView);
        String filePath = getIntent().getStringExtra("File_Path");

        textView.setText(readFile(filePath));

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        Toast.makeText(ReadActivity.this, "onKeyUp", Toast.LENGTH_SHORT).show();
        return false;
    }

but it doesn't work. I think it is disabled because of scrollView.

How to detect touch event at scrollView?

Upvotes: 2

Views: 2166

Answers (2)

Daniyar Kayirbolatov
Daniyar Kayirbolatov

Reputation: 163

So you want to observe if scroll is moving up or down.

Firstly checkout docs

Implementation:

scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

    }
});

If you are checking if it up or down motion just simply compare scrollX and oldScrollX, horizontally scrollY and oldscrollY

Upvotes: 0

ariefbayu
ariefbayu

Reputation: 21979

As you've already mentioned in the question, onTouchEvent do have ACTION_UP that is meant to handle when touch up.

Upvotes: 2

Related Questions