Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:36:22+00:00 2026-05-25T17:36:22+00:00

I have a java file that its setContentView is to another java file… Here

  • 0

I have a java file that its setContentView is to another java file…

Here is the first java file

    package dalton.metzler.occupied;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;


public class PlayActivity extends Activity{

    Play ourView;

    LinearLayout linear;
    TextView text;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        ourView = new Play(this);
        setContentView(ourView);
    }



}

And here is the file thats linking to it as the set contentview there is not speical code you need to look at just showing so you can see what it is.

And see exactly what i mean about the text thing i am trying to do

    package dalton.metzler.occupied;

import java.util.Random;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;


    public class Play extends View {

    Bitmap gBall1, gBall2, gBall3, gBall4, gBall5, gBall6, gBall7, gBall8, gBall9, gBall10, gBall11, gBall12, gBall13;

    float changingY, changingY2, changingY3, changingY4, changingY5, changingY6, changingY7, changingY8, changingY9, changingY10, changingY11, changingY12, changingY13;


    public Play(Context context) {
        super(context);


        gBall1 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
        gBall2 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
        gBall3 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
        gBall4 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
        changingY = 0;
        changingY2 = -110;
        changingY3 = -220;
        changingY4 = -330;
        changingY5 = -440;
        changingY6 = -550;
        changingY7 = -660;
        changingY8 = -770;
        changingY9 = -880;
        changingY10 = -990;
        changingY11 = -1100;
        changingY12 = -1210;
        changingY13 = -1320;

    }

    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(gBall1, (canvas.getWidth()/2), changingY, null);
    canvas.drawBitmap(gBall2, (canvas.getWidth()/2), changingY2, null);
    canvas.drawBitmap(gBall3, (canvas.getWidth()/2), changingY3, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY4, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY5, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY6, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY7, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY8, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY9, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY10, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY11, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY12, null);
    canvas.drawBitmap(gBall4, (canvas.getWidth()/2), changingY13, null);
    if (changingY < canvas.getHeight()){
        changingY += 5;

    }else{
        changingY = -600;
    }
    if (changingY2 < canvas.getHeight()){
        changingY2 += 5;

    }else{
        changingY2 = -600;
    }
    if (changingY3 < canvas.getHeight()){
        changingY3 += 5;

    }else{
        changingY3 = -600;
    }
    if (changingY4 < canvas.getHeight()){
        changingY4 += 5;

    }else{
        changingY4 = -600;
    }
    if (changingY5 < canvas.getHeight()){
        changingY5 += 5;

    }else{
        changingY5 = -600;
    }
    if (changingY6 < canvas.getHeight()){
        changingY6 += 5;

    }else{
        changingY6 = -600;
    }
    if (changingY7 < canvas.getHeight()){
        changingY7 += 5;

    }else{
        changingY7 = -600;
    }
    if (changingY8 < canvas.getHeight()){
        changingY8 += 5;

    }else{
        changingY8 = -600;
    }
    if (changingY9 < canvas.getHeight()){
        changingY9 += 5;

    }else{
        changingY9 = -600;
    }
    if (changingY10 < canvas.getHeight()){
        changingY10 += 5;

    }else{
        changingY10 = -600;
    }
    if (changingY11 < canvas.getHeight()){
        changingY11 += 5;

    }else{
        changingY11 = -600;
    }
    if (changingY12 < canvas.getHeight()){
        changingY12 += 5;

    }else{
        changingY12 = -600;
    }
    if (changingY13 < canvas.getHeight()){
        changingY13 += 5;

    }else{
        changingY13 = -600;
    }
    invalidate();   
    }       
}

How can i add text to the app? Like a textview but not in the xml because i can’t do this (i think)
I want to add like the text: Score: 0 to the screen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:36:23+00:00Added an answer on May 25, 2026 at 5:36 pm

    Right now you cannot added another view to your custom View as it extends the View class. You will need to extend a viewgroup class to add other views.

    Create a linear layout and add the play view and the textview to that and set the linear layout in the setContentView function.

    If you just need to draw text on playview, there is the canvas.drawText function.

    I think your drawText method is wrong. Try this.

        Paint orangePaint = new Paint();
        orangePaint.setColor(Color.BLACK);
    
        canvas.drawText("test", 50, 50, orangePaint);
    

    This should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java JAR file that is triggered by a SQL server job.
i have a java ee project which has a text file that uses a
I have a text file that I want to edit using Java. It has
I have a Java process that opens a file using a FileReader. How can
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have a Java program that is launched by a batch file with a
I have a Java application that makes heavy use of a large file, to
I have a java app that uses log4j. Config: log4j.rootLogger=info, file log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=${user.home}/logs/app.log log4j.appender.file.layout=org.apache.log4j.PatternLayout
In my Java code I have function that gets file from the client in
I have made a java application that stores data from a .csv file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.