You need to implement the other constructors from the superclass. I
don't recall which ones matter here, but the one that you have (only
takes a Context as a method argument) is not going to work.
On Apr 30, 12:14 pm, Amidos <[EMAIL PROTECTED]> wrote:
> I have created my ownView (extend class View) and override function
> onDraw() in it
> I wanted to use it in my xml file design :D
> but when i put it inside the file an error happens when the program
> runs so if anyone can help me to do so as i make whole imnterface
> using xml and i wanna add this new class in between.
>
> The code:
> This is the new view:
> package com.android.mobi3.player;
>
> import android.content.Context;
> import android.graphics.Canvas;
> import android.graphics.Paint;
> import android.graphics.RectF;
> import android.graphics.Paint.Style;
> import android.view.View;
>
> /**
> *
> * @author Ahmed Abdel Samea
> * This Class is used to provide a view to user to draw
> * the seek bar.
> *
> */
> public class SeekTimer extends View {
>
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
> /* Variables Area
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
>
> //width of the drawing
> protected final int ARCSTROKEWIDTH = 20;
> //values
> protected int mySecondsPassed = 0;
> protected int mySecondsTotal = 0;
> //used to draw the timer by no. and seek bar
> protected final Paint myArcSecondPaint = new Paint();
> protected final Paint myArcMinutePaint = new Paint();
> protected final Paint myCountDownTextPaint = new Paint();
>
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
> /* Constructor
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
> /
> *---------------------------------------------------------------------------
> */
>
> public SeekTimer(Context context) {
> super(context);
> /******************************************************/
> /**---- Setting the timer and seek bar drawer ----*/
> /******************************************************/
>
> // Black text for the countdown
> this.myCountDownTextPaint.setARGB(150, 0, 0, 0);
> this.myCountDownTextPaint.setTextSize(110);
> this.myCountDownTextPaint.setFakeBoldText(true);
>
> // Our arc fill be a lookthrough-red.
> this.myArcMinutePaint.setARGB(150, 170, 0, 0);
> this.myArcMinutePaint.setAntiAlias(true);
> this.myArcMinutePaint.setStyle(Style.STROKE);
> this.myArcMinutePaint.setStrokeWidth(ARCSTROKEWIDTH);
>
> this.myArcSecondPaint.setARGB(200, 255, 130, 20);
> this.myArcSecondPaint.setAntiAlias(true);
> this.myArcSecondPaint.setStyle(Style.STROKE);
> this.myArcSecondPaint.setStrokeWidth(ARCSTROKEWIDTH / 3);
> }
>
> // ===========================================================
> // Getter & Setter
> // ===========================================================
>
> public void updateSecondsPassed(int someSeconds){
> this.mySecondsPassed = someSeconds;
> }
>
> public void updateSecondsTotal(int totalSeconds){
> this.mySecondsTotal = totalSeconds;
> }
>
> public int getSecondsPassed(){
> return mySecondsPassed;
> }
>
> @Override
> protected void onDraw(Canvas canvas) {
> /* Calculate the time left,
> * until our pizza is finished. */
> int secondsLeft = this.mySecondsTotal - this.mySecondsPassed;
>
> if(secondsLeft>0){
> // At least one second left
> float angleAmountMinutes = ((this.mySecondsPassed *
> 1.0f)
> /
> this.mySecondsTotal)
> * 360;
> float angleAmountSeconds = ((60 -secondsLeft % 60) *
> 1.0f)
> / 60
> * 360;
>
> /* Calculate an Rectangle,
> * with some spacing to the edges */
> RectF arcRect = new RectF(ARCSTROKEWIDTH / 2,
> ARCSTROKEWIDTH / 2,
> this.getWidth() -
> ARCSTROKEWIDTH / 2,
> this.getHeight() -
> ARCSTROKEWIDTH / 2);
>
> // Draw the Minutes-Arc into that rectangle
> canvas.drawArc(arcRect, -90, angleAmountMinutes,
>
> this.myArcMinutePaint);
>
> // Draw the Seconds-Arc into that rectangle
> canvas.drawArc(arcRect, -90, angleAmountSeconds,
>
> this.myArcSecondPaint);
>
> }
> }
>
> }
>
> code and I wrote in the xml:(I write it in relative layout)
>
> Line 23: <SeekTimer android:id="@+id/seek_bar"
> android:layout_width="50px"
> android:layout_height="50px"
> android:layout_centerHorizontal="true"/>
>
> The error that i get:
>
> ComponentInfo{com.android.mobi3.player/
> com.android.mobi3.player.PlayerGUI}
> android.view.ViewInflate$Inflate Exception: Binary XML file line
> #23:Error inflating class SeekTimer.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---