Note that there are some explanatory texts on larger screens.

plurals
  1. POcanvas.DrawRect causes app auto quit
    primarykey
    data
    text
    <p>I follow the original android API and use the monodroid to write a very simple CustomView to draw a rectangle. Once I enter the application, it automatically quites. While I write a pure android with eclipse, it works fine. Or when I delete the drawRect method code, it works fine too. Does anyone know this or something wrong I did? </p> <p>Here attaches the apps code:</p> <p>[Activity1.cs]</p> <pre><code>int count = 1; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById&lt;Button&gt;(Resource.Id.MyButton); LinearLayout layoutRoot = FindViewById&lt;LinearLayout&gt;(Resource.Id.LayoutRoot); layoutRoot.AddView(new DrawableView(this)); button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; } </code></pre> <p>[DrawableView.cs]</p> <pre><code>protected override void OnDraw(Android.Graphics.Canvas canvas) { base.OnDraw(canvas); canvas.DrawRect(new Rect(10, 10, 100, 100), new Paint { Color = Color.Red }); } </code></pre> <p>this is the code I use in the eclipse:</p> <pre><code>public class DrawableView extends View { public DrawableView(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawRect(new Rect(10, 10, 110, 110), paint); } </code></pre> <p>}</p> <p>Thanks a lot. Howard</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload