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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:46:29+00:00 2026-05-14T00:46:29+00:00

Ok right , i asked how to create a random number from 1-100 for

  • 0

Ok right , i asked how to create a random number from 1-100 for android and i came to this

    TextView tv = new TextView(this);

    int random = (int)Math.ceil(Math.random()*101); 

    tv.setText("Your Number Is..."+ random );

What this does is create the default kinda “hello world” style text view and says “Your Number Is…. [Then Random Number]

My problem is that i cant change the layout of this text , because it is not defined in XML, if someone could tell me how to change the style , or like make the random number into a string so i could use it for any Textview layout that would be great ..

Thanks 🙂

  • 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-14T00:46:30+00:00Added an answer on May 14, 2026 at 12:46 am

    You could also do something like this.

    Define your string in strings.xml like:

    <string name="your_number_is">Your number is <xliff:g id="number">%s</xliff:g>.</string>
    

    Create a TextView in a layout xml:

    <TextView android:id="@+id/your_number_is"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/your_number_is"
        android:gravity="center"
        android:textSize="100dip"
        />
    

    Then your code would look like:

    TextView tv = (TextView) findViewById(R.id.your_number_is);
    int random = (int)Math.ceil(Math.random()*101);
    tv.setText(getString(R.string.your_number_is, random));
    

    This will make it a lot easier when you later on would like to change your text or maybe localize your app.

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

Sidebar

Related Questions

I have asked this before but I didn't get the question right so the
I'm new to Java and have been asked to create an applet/servlet (not sure
We are using 2.x spring security right now. I am asked to build an
Right now when I run this it keeps clicking on the same button every
Right now, I've just some code which fetches the picture from the URL directly.
Sorry if already asked, but I can't find anything on this. I am moving
I had asked this question in a much more long-winded way a few days
I'm creating a Ruby on Rails application, and I'm trying to create/login/logout users. This
Before answering this question, understand that I am not asking how to create my
Simple question, asked before but no one gave me the right answer so I'm

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.