开发者

Android: onTouchEvent for textView

开发者 https://www.devze.com 2022-12-22 08:39 出处:网络
I\'m beginner developing developing small application. I have 3 textview on screen, when i touch the any one of the开发者_StackOverflow中文版 view it should navigate to next new screen, how to do this

I'm beginner developing developing small application. I have 3 textview on screen, when i touch the any one of the开发者_StackOverflow中文版 view it should navigate to next new screen, how to do this help me

Thanks,

Suhani


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;
    }
});


You can set an OnClickListener for pretty much any view not just buttons, for your case the code would be:

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

                }
            });

Assuming you're navigating between activities, the navigation code would be as follows:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号