开发者

Tab longClick problem in android

I have 5 tabs and I want to call a function on it's longclick (onLongClick()). The longclick is working but when I release the touch the click (onClick()) function is also called along wit开发者_如何学Goh it. Please anyone help me on this problem.


It happens. I also had the same problem while implementing OnItemClickListener and OnItemLongClickListener.

You can accomplish this with a vairable value:

int i=0;//declare this as outside all methods
void onClick(...)
{
  if(i==0)
  {//your code
  }

  else
  {
    i=0;
  }
}

void OonLongClick(...)
{
   //your code
   i=1;
}

this won't stop onClick from being called on long click but will fulfill your purpose by not performing the task you want to perform only on onClick().

Another method is to call another activity using intent from method onLongClick(). This will stop onClick() from being called because the control will move to another activity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜