开发者

OnTouchListener not working

开发者 https://www.devze.com 2023-01-25 19:44 出处:网络
I have a few buttons in a tab layout for which the OnClickListener works fine. The purpose of these buttons is to 开发者_JS百科start a new activity when clicked upon. I want my code to work for the to

I have a few buttons in a tab layout for which the OnClickListener works fine. The purpose of these buttons is to 开发者_JS百科start a new activity when clicked upon. I want my code to work for the touch mode of the phone as well. In other words I wanted to know how to implement the OnTouchListener for the code. Currently I have something like

public boolean onTouch(View v, MotionEvent event) {
  startActivity(new Intent().setClass(this, OtherActivity.class));
  return true;
}

I am just thinking about it the same way as I would think about the onClick() method but apparently I am wrong.

Any help in this matter would be appreciated. Thanks!


Touching a button on the screen should generate click events the same as using a hardware keypad. Try using the Log object and LogCat to see when methods are called.

0

精彩评论

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