denza
denza

Reputation: 1298

switch executes both cases in options menu

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
    switch(item.getItemId())
    {
        case R.id.item1: fukncijaD();
        case R.id.item20: funkcijaOceni();
        return true;
    }

    return super.onMenuItemSelected(featureId, item);
}

//here is the xml for the menu

<?xml version="1.0" encoding="utf-8"?>
    <menu
        xmlns:android="http://schemas.android.com/apk/res/android">
         <item android:title="Зачувај" 
          android:id="@+id/item1"></item>
         <item android:id="@+id/item20" android:title="Оцени"></item>
         <item android:id="@+id/item3" android:title="Пост на ФБ"></item>

    </menu>

When I check the value in case R.id.item1: fukncijaD(); it goes as it should with funckcijaD(), and then continues with the second case as if there were no cases...

Upvotes: 2

Views: 1557

Answers (1)

user936414
user936414

Reputation: 7634

Put break

switch(item.getItemId())
 {
 case R.id.item1:fukncijaD();break;
 case R.id.item20:funkcijaOceni();break;

 }

Upvotes: 3

Related Questions