Hoi

I try to create my custom view inside a linearlayout. For example

<View  android:id="@+id/ViewPaint"
class="com.example.android.helloactivity.HelloActivity$DrawingView"/>

In the java source I created a DrawingView class which extends View.
Unfortunatly it does not get instantiated. I tried to overwrite the
ondraw() but without success :-(

Help is very much appreciated.
Jasper

Java Code
   public static class DrawingView extends View
    {
        private final Paint mPaint;
        /*
         * Constructor that is called when inflating a view from XML.
         */
        DrawingView(Context context, AttributeSet attrs){
                super(context,attrs);

            mPaint = new Paint();
            mPaint.setAntiAlias(true);
            mPaint.setARGB(255, 255, 255, 255);
        }

        @Override
        protected void onDraw(Canvas canvas) {
                float yPos;
                float xPos;
                int   xOffset = 20;
                int   yOffset = 50;
                int   cxScreen = canvas.getWidth();
                int   cyScreen = canvas.getHeight();
                int   cx = cxScreen - (2*xOffset);
                int   cy = cyScreen - (2*yOffset);
                int   cxStepSize = cx/10 - 1;
                int   cyStepSize = cy/10 - 1;

            // Makes the complete screen white!
            //canvas.drawColor(0xFFFFFFFF);
            yPos = (float)yOffset;
            xPos = (float)xOffset;
            for (int i=0; i <= 10; i++)
            {   // xstart, ystrt,xend,yend
                canvas.drawLine((float)xOffset, yPos, (float)cx, (float)
yPos, mPaint);
                yPos += cyStepSize;
            }
            for (int i=0; i <= 10; i++)
            {   // xstart, ystrt,xend,yend

                canvas.drawLine((float)xPos, (float)yOffset, (float)xPos,
(float)cy, mPaint);
                xPos += cxStepSize;
            }
        }
    }

XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="Please select a planet:"
    />

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/planet_prompt"
    />
     <TextView android:id="@+id/dateDisplay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No date yet"/>

       <Button android:id="@+id/pickDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Change the date"/>

    <TextView android:id="@+id/timeDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No time yet"/>

    <Button android:id="@+id/pickTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Verander the time"/>

<View  android:id="@+id/ViewPaint"
class="com.example.android.helloactivity.HelloActivity$DrawingView"/>
</LinearLayout>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to