mardi 14 juin 2016

How create a view inside activity?

My goal is to create a simple ball in the mobile screen center so I can move it around the screen as they drag my finger.

For that I wanted to use the Canvas and bitmap (I do not know if it's the best way seen as already said I am new in the Android world).

I created a function in my Activity so that when a button was clicked, a activity containing the script to the canvas design was created (Again not know if it's the best way. In a php script or javascript I would create the ball in the function itself). My code is as follows:

public void StartGame(View v)  {
       Intent i = new Intent(MainActivity.this, ball.class);
       startActivity(i);
    }

By doing this it should call the following activity:

com.teste package;
    
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.util.AttributeSet;
    import android.view.View;
    
    
    public class ball extends View {
    
        Paint pincelPreto private;
        Paint pincelAmerelo private;
    
        Public ball (Context context) {
            super (context);
        }
    
        Public ball (Context context, attributeSet attrs) {
            super (context, attrs);
    
            setBackgroundColor (Color.LTGRAY);
            pincelPreto = new Paint ();
            pincelPreto.setColor (Color.BLACK);
            pincelAmerelo = new Paint ();
            pincelPreto.setColor (Color.YELLOW);
    
            setFocusable (true);
        }
    
        @Override
        protected void onDraw (Canvas canvas) {
            super.onDraw (canvas);
    
            canvas.drawCircle (200, 200, 200, pincelAmerelo);
        }
    }

And both draw a ball at every location ... But I get the following error:

Android.content.ActivityNotFoundException: Unable to find explicit activity class {com.teste / com.teste.ball}; have you declared this activity in your AndroidManifest.xml?

What am I doing wrong?

OBS.: I maybe call activity because i dont know the real name of it.

Aucun commentaire:

Enregistrer un commentaire