开发者

Android: onTouchEvent for textView

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜