Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Invoke routine in class from other class (not activity) in JAVA for Android
  2. public static void addFruit(MainGamePanel context){
  3.  
  4. fruitInventory();
  5. //add 10 apples with random coordinates
  6.  
  7. for (int i = 0; i < 10; i++) {
  8. Random Rnd = new Random();
  9. apple nextApple = new apple(BitmapFactory.decodeResource(context.getResources(),
  10.                   fruitResources.get(Rnd.nextInt(fruitResources.size()))));
  11. //add them to the arraylist
  12. MainGamePanel.AppleList.add(nextApple);
  13. }
  14.        
  15. public class Button{
  16. private Context context;
  17. public Button(Context context)
  18. {
  19. this.context = context;
  20. }
  21. ....
  22. fruitmanager.addfruit(context);
  23. ...
  24.        
  25. new Button(this);