Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Or statement in switch/case ?

Is it possible to use an OR statement in a switch/case structure? Suppose I want to do the same thing when clicking on two different items.

I tried

(case R.id.bOne || case R.id.tvOne):

and

case (R.id.bOne || R.id.tvOne):

But none of them seem to work..

like image 588
Matthias Vanb Avatar asked Nov 28 '22 21:11

Matthias Vanb


2 Answers

This will work:

case R.id.bOne:
case R.id.tvOne:
  // do your stuff
like image 171
Emanuel Moecklin Avatar answered Dec 17 '22 01:12

Emanuel Moecklin


Try this:

switch(id){
    case R.id.bOne:
    case R.id.tvOne:
        // do your stuff here
        break;
    case R.id.x:
        // do your stuff here
        break;
    default:
        // do your stuff here
} 
like image 32
hin Avatar answered Dec 17 '22 01:12

hin