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 8183375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:08:33+00:00 2026-06-07T01:08:33+00:00

My purpose is to make an Bitmap image which shows user supplied text, and

  • 0

My purpose is to make an Bitmap image which shows user supplied text, and the image can later be saved into cache.

After calling TextView.setText() and TextView.invalidate(), the TextView is not being updated as I expected. It still draws previous texts on Canvas.

@Override
public void onClick(View v) {
    // tv is a TextView and et is an EditText.
    tv.setText(et.getText().toString());
    tv.invalidate();
    // if measure() isn't called, getMeasuredWidth() returns previous value.tv.measure(0, 0);

    int screenWidth = (int) tv.getMeasuredWidth();
    int screenHeight = (int) tv.getMeasuredHeight();

    if (screenHeight * screenWidth != 0) {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                                                    screenWidth, screenHeight);
        Bitmap testB;

        testB = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(testB);

        tv.draw(c);
        // tv draws previous String on Canvas c.

        iv = (ImageView) findViewById(R.id.image);
        iv.setLayoutParams(layoutParams);
        iv.setBackgroundColor(Color.RED);
        iv.setImageBitmap(testB);
    }
}

The document says

public void invalidate ()

Invalidate the whole view. If the view is visible,
onDraw(android.graphics.Canvas) will be called at some point in the
future. This must be called from a UI thread. To call from a non-UI
thread, call postInvalidate().

Does it mean I should override the onDraw() method?

  • 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-06-07T01:08:35+00:00Added an answer on June 7, 2026 at 1:08 am

    I found the solution… (may be a solution)

    It is needed to add this line before calling draw():

    tv.layout(0, 0, screenWidth, screenHeight);
    

    I think the width and height aren’t updated yet, because getWidth() returns previous value.

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

Sidebar

Related Questions

I am trying to make general purpose image display class which receives two parameters,
I worked on a nice force download file script which purpose is to make
Which css hacks we use to make layout cross browser compatible Can pass W3C
How to make script very interactive? Script purpose: Get user entered number and find
I am helping to make a website in PHP which is an ERP purpose
I'd like to make a program that can enter login credentials for authentication purpose
I'm creating custom control - image button. The purpose is to make button without
I'm trying to make a program, which is basically a shopping list. The purpose
I am trying to create a Validation in a reusable fashion. Purpose: Make the
Purpose: To make sure some elements couldn't be modified, I disabled some elements once

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.