views:

29

answers:

1
  public class SimpleOptionMenu extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.icon:     Toast.makeText(this, "You pressed the icon!", Toast.LENGTH_LONG).show();
                            break;
        case R.id.text:     Toast.makeText(this, "You pressed the text!", Toast.LENGTH_LONG).show();
                            break;
        case R.id.icontext: Toast.makeText(this, "You pressed the icon and text!", Toast.LENGTH_LONG).show();
                            break;
    }
    return true;
}
}

I have res/menu/menu.xml file created and filled. When this class extends just Activity, it works fine, but when i used ListActivity, it keeps crashing. I noticed this when i was working with another app that uses list activity. [after searching long and hard. :|]

A: 

Without seeing a stack trace, it's hard to know exactly what's going on, but, ListActivity requires that the various elements in the main.xml have certain specific ids.

jwriteclub