Android: onTouchEvent for textView

I am starting to develop a small application. I have 3 textviews on the screen, when I touch any of them, it should go to the next new screen, how to do it to me.

Thank,

Suhani

+3
source share
2 answers
yourTextView.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            // do something here when the element is clicked
            ScreenManager.setCurrent(new YourNewPage());
        }

        // true if the event was handled
        // and should not be given further down to other views.
        // if no other child view of this should get the event then return false

        return true;
    }
});
+7
source

You can install OnClickListener for almost any kind, and not just buttons, for your code:

YourTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //The Navigation code

                }
            });

Assuming you move between actions, the navigation code will look like this:

Intent myIntent = new Intent(CurrentActivityName.this,NextActivityName.class);
startActivity(myIntent);
0
source

Source: https://habr.com/ru/post/1735405/


All Articles