0

How can I draw image from a class? In the main I create a object with a random number, in the paint class I want to handle more stuff not just paint, because of that i think it´s best that i have a another class that draws my picture on top off the "main" background with its buttons etc..

I have read about canvas and bitmap. But cant figure out how to implement it, because I also want to change the picture i a method in this class later in my game.

Should the new class extend ActionBarActivity or View??

Can just some helpful soul give some example to guide me a little..

example of the class I create objects of:

public class paint {

    public Svar(int aNumber) {
        if (aNumber == 1) {
        //Paint something
                }
        if (aNumber == 2) {
                //Paint something else
        }
        if (aNumber == 3) {
                //Paint something else
        }
        if (aNumber == 4) {
                //Paint something else
        }
        if (aNumber == 5) {
                //Paint something else
        }
    }

}
joao2fast4u
  • 6,868
  • 5
  • 28
  • 42
user3356636
  • 115
  • 1
  • 11

1 Answers1

0

The thing you want is creating a Custom View and overriding the onDraw method. After creating your custom view class you can set the content view in your Activity to that View. e.g.

CustomView myCustomView = new CustomView();
setContentView(myCustomView);

You can use the canvas helper functions to draw your bitmap.

Here's a good tutorial for custom views: http://www.vogella.com/tutorials/AndroidCustomViews/article.html

Here's another example emphasizing overriding the onDraw method: Draw in Canvas by finger, Android

Community
  • 1
  • 1
C.d.
  • 9,932
  • 6
  • 41
  • 51