android - 使用 and(&) 运算符在 switch case 期间出现重复大小写错误

标签 android c++ touch

switch (v.getId() & event.getAction()) {
    case R.id.report_stype & MotionEvent.ACTION_DOWN:
        spinnertype();

        break;
    case R.id.report_sapprove & MotionEvent.ACTION_DOWN:

        break;

    }

两种情况都显示重复错误..如何解决?

最佳答案

您确定要按位并使用 & 运算符吗?

这实际上并不能保证两个不同的值。

例如,ACTION_DOWN 可能具有值为 1 的那些位,它们在您的两种情况下都屏蔽了 id。

尝试重新思考逻辑。

你可以这样做:

switch (v.getId() ) {
case R.id.report_stype:
    if( event.getAction() == MotionEvent.ACTION_DOWN)
       spinnertype();

    break;
case R.id.report_sapprove:
    if( & event.getAction() ==  MotionEvent.ACTION_DOWN)
        // do whatever

    break;

}

希望这对您有所帮助。

关于android - 使用 and(&) 运算符在 switch case 期间出现重复大小写错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19721819/

相关文章:

java - Android API 的客户端等待时间

c++ - 'pcap_loop' 没有记录数据包,甚至没有运行

c++ - 在 OpenCV 中创建矩阵后调整其大小

android - 我可以使 ListView 项目不可选吗?

android - 使用键盘时,ListView 不会滚动到末尾

android - sencha touch Uncaught TypeError : Cannot read property 'isReady' of undefined sencha-touch-all. js:21

android - 如何使动画在触摸时开始并在再次触摸时停止?

jquery - li 标签没有触摸事件

android - android中的onclick监听器

c++ - 从 Qt5 ColorDialog 中删除颜色渐变窗口