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);
精彩评论