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

  • SEARCH
  • Home
  • 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 6963781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:50:21+00:00 2026-05-27T15:50:21+00:00

I have a custom view in my layout and I also have a TextView

  • 0

I have a custom view in my layout and I also have a TextView in the layout as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:layout_alignParentTop="true" android:layout_centerInParent="true"
    android:text="Tiny" android:orientation="vertical">

<my.package.drawView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />


<TextView android:text="Application Name" android:id="@+id/appName"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:textSize="30px" android:textStyle="italic" />
</LinerLayout>

I set the reference to the TextView in the onCreate method of the activity and in the onDraw method of my custom view, I change the text of the TextView as follows:

public void onDraw(Canvas canvas) {
    tv.setText("player score: "+score);
}

But setting the text in the ondraw method causes it to go in an infinite loop.
Could someone please tell me how do I update the text of the TextView in or after the onDraw method of the custom view is called.

  • 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-27T15:50:21+00:00Added an answer on May 27, 2026 at 3:50 pm

    When you change a visual thing in the current view i.e. textview in this case. The entire visible region is redrawn and as part of that my.package.drawView is told to draw itself and hence the infinite loop.

    Changing the visual properties in onDraw should be avoided and the design is incorrect.

    Maybe you need some sort of timer to update the score or somewhere else that increases the score when something happens in the game?

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

Sidebar

Related Questions

I have a ViewFlipper defined that contains 3 views... <?xml version=1.0 encoding=utf-8?> <ViewFlipper xmlns:android=http://schemas.android.com/apk/res/android
For my custom view I have also defined a custom attribute for keep id
i have a Custom view ... package nan.salsa.goal.customview; import android.R; import android.content.Context; import android.graphics.Canvas;
Ok so I have a layout which looks something like this: LinearLayout TextView LinearLayout
I have a custom spinner layout with an image and a text view but
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I have a custom control/view that observes the direction of a gesture within its
I have a custom-made view that extends the View class. I would like 2
I have a simple custom view that is connected via outlet to a NIB.
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and

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.