Change Activity via Options Menu


Last Updated: 2010-10-27 23:18:50
  1. gorjan

    gorjan New Member

    Hi All,

    I'm really new to Android development, so I have one basic question.
    I have the following code. I want to change the screen(the Activity) via Options menu:
    Code (Text):
    1.  
    2.  
    3. @Override
    4.     public boolean onOptionsItemSelected(MenuItem item) {
    5.         // TODO Auto-generated method stub
    6.         switch (item.getItemId())
    7.         {
    8.         case R.id.item01:
    9.             Intent intentItem1 = new Intent(this, Item1Activity.class);
    10.             startActivityForResult(intentItem1, 0);
    11.             //startActivity(intentItem1);
    12.             return true;
    13.            
    14.         default: return super.onOptionsItemSelected(item);
    15.         }
    16.        
    17.     }
    18.  
    But the activity doesn't change and the error message I receive while debugging is that "The resource doesn't exist"

    Any ideas?

    Thanks in advance.

    Advertisement
  2. sscAndroid

    sscAndroid Member

    Your code for changing the activity looks solid.

    If you receive the error that a resource cannot be found, that means you're accessing a xml resource that just isn't there. In your example, the only line where you access a resource is your
    Code (Text):
    1.  
    2. case R.id.item01:
    3.  
    line. You should check if your menuitem is really spelled that way.

    Besides, your compiler should tell you exactly where and what is causing the error, just check the logcat output.

Share This Page