fork download
  1. public class MyActivity extends Activity {
  2. SubMenu mSubmenu;
  3.  
  4. @Override
  5. public boolean onCreateOptionsMenu(Menu menu) {
  6. mSubmenu = menu.addSubMenu("foo");
  7. return true;
  8. }
  9.  
  10. @Override
  11. public boolean onPrepareOptionsMenu(Menu menu) {
  12. mSubmenu.clear();
  13. int n = (int) (Math.random() * 10) + 1;
  14. for (int i = 0; i < n; i++) {
  15. final double value = Math.random();
  16. MenuItem item = mSubmenu.add(String.valueOf(value));
  17. item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  18. public boolean onMenuItemClick(MenuItem item) {
  19. new AlertDialog.Builder(MyActivity.this)
  20. .setMessage("value=" + value)
  21. .setPositiveButton("OK", null).show();
  22. return true;
  23. }
  24. });
  25. }
  26. return true;
  27. }
  28. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty