public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
// TODO Auto-generated method stub
if(velocityX<-10.0f)
{
mCurrentStateLayout = mCurrentStateLayout == 0 ? 1 : 0;
switchLayoutStateTo(mCurrentStateLayout);
}
return true;
}
});语句mCurrentStateLayout = mCurrentStateLayout == 0?1: 0;是什么意思?
发布于 2015-06-20 01:18:58
mCurrentStateLayout = mCurrentStateLayout == 0 ? 1 : 0;这是Java中的ternary操作符。它本质上是if else语句的简写。
如果mCurrentStateLayout 为等于0,则该语句为true,并为mCurrentStateLayout赋值1。
如果mCurrentStateLayout is not等于0,则该语句为false,并为mCurrentStateLayout赋值0。
发布于 2015-06-20 02:15:38
在代码中显示它。这是你粘贴在这里的代码的模拟:
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
// TODO Auto-generated method stub
if(velocityX<-10.0f)
{
if (mCurrentStateLayout == 0) {
mCurrentStateLayout = 1;
} else {
mCurrentStateLayout = 0;
}
switchLayoutStateTo(mCurrentStateLayout);
}
return true;
}
});https://stackoverflow.com/questions/30943694
复制相似问题