1

Currently I have a class called MapActivity that extends AppCompatActivity, and I need this because I have a acitivity_map.xml, but the thing is, I want to extend View, so that I can draw things on this activity.

How can I achive this ?

Tim
  • 39,651
  • 17
  • 123
  • 137
Jozo
  • 117
  • 7

1 Answers1

2

Recently i had the same question. Here is what i got: Create your own view:

public class CustomView extends View

Override the onDraw() method like this:

 @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.save();
        //draw something
        canvas.restore();
 }

In your Activity in onCreate:

setContentView(R.layout.activity_name);
    com.XXX.XXX.CustomView cV = (com.XXX.XXX.CustomView) findViewById(R.id.customView);

And in the xml:

<com.XXX.XXX.CustomView
        android:id="@+id/customView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
XxGoliathusxX
  • 864
  • 11
  • 31
  • This answer could be useful, if you're looking for this issue http://stackoverflow.com/questions/3739661/error-inflating-when-extending-a-class – Mitro Apr 11 '17 at 17:16