3

我正在开发开发小型应用程序的初学者。我在屏幕上有 3 个 textview,当我触摸它应该导航到下一个新屏幕的任何一个视图时,如何做到这一点对我有帮助

谢谢,

苏哈尼

4

2 回答 2

7
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;
    }
});
于 2010-04-30T15:12:31.823 回答
0

您可以为几乎任何视图设置 OnClickListener,而不仅仅是按钮,对于您的情况,代码将是:

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

                }
            });

假设您在活动之间导航,导航代码如下:

Intent myIntent = new Intent(CurrentActivityName.this,NextActivityName.class);
startActivity(myIntent);
于 2016-08-31T10:42:27.883 回答