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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:04:54+00:00 2026-06-02T03:04:54+00:00

Can someone please try and explain this code for me, I don’t really understand

  • 0

Can someone please try and explain this code for me, I don’t really understand any of it and nowhere on the web seems to explain it. I’ve brought a copy of ‘Android Development for Dummies’ and it hasn’t really helped me.

private TextView txtMineCount;
private TextView txtTimer;
txtMineCount = (TextView) findViewById(R.id.MineCount);
txtTimer = (TextView) findViewById(R.id.Timer);

// set font style for timer and mine count to LCD style
Typeface lcdFont = Typeface.createFromAsset(getAssets(),
    "fonts/lcd2mono.ttf");
txtMineCount.setTypeface(lcdFont);
txtTimer.setTypeface(lcdFont);

Thanks in advance guys.

  • 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-02T03:04:56+00:00Added an answer on June 2, 2026 at 3:04 am
    private TextView txtMineCount;
    private TextView txtTimer;
    

    This declares two local variables that can hold references to a TextView. At first they do not point to anything…so you have to assign them.

    txtMineCount = (TextView) findViewById(R.id.MineCount);
    txtTimer = (TextView) findViewById(R.id.Timer);
    

    Here we assign the two variables. We call a method of the framework to do a lookup among the text-based widgets that have been created by an ID. Importantly we’re not creating these widgets here. We are just finding the already-allocated object instances which correspond to some ID constants we use to name them.

    It’s not necessarily “safe” to assume these lookups succeed in the general case, because View.findViewById() can return null. But the person who wrote this code is assuming that there have indeed been TextView objects created elsewhere in the code which have those particular IDs.

    (If they’re wrong about that, then trying to set the typeface on txtMineCount or txtTimer will just cause an exception…)

    // set font style for timer and mine count to LCD style
    Typeface lcdFont = Typeface.createFromAsset(getAssets(),
        "fonts/lcd2mono.ttf");
    

    Android has some default fonts that ship with the system. But this program wants to make use of a TrueType Font File which has been embedded in the font subdirectory of the application’s assets (basically a bunch of files that travel along inside your application bundle). This creates a Typeface object suitable for applying to a TextView out of that file.

    txtMineCount.setTypeface(lcdFont);
    txtTimer.setTypeface(lcdFont);
    

    This simply sets the typeface used by the two TextViews to the font from above.


    Note that you can get an equivalent effect without the intermediate variables. This code should do the same thing as what you posted:

    ((TextView)findViewById(R.id.MineCount)).setTypeface(
        Typeface.createFromAsset(getAssets(), "fonts/lcd2mono.ttf"));
    
    ((TextView)findViewById(R.id.Timer)).setTypeface(
        Typeface.createFromAsset(getAssets(), "fonts/lcd2mono.ttf"));
    

    But it’s harder to read this way, and by not saving intermediate results in variables you can end up computing that intermediate result multiple times. For instance, the Typeface.createFromAsset code is run twice with the same parameters when you write it this way.

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

Sidebar

Related Questions

Can someone please explain how to understand a logcat from an android force close.
Can anyone please explain exactly what this code and its components are doing? I
Can someone please explain Why my first examples don't work, and why adding in
I get Segmentation Fault when I try to run my program. Can someone please
Can someone please explain to me the difference between the AppSettings and ApplicationSettings sections
can someone please show me documentation on this method? i have the following line:
Can someone please explain the major differences between Scala, Groovy and Clojure. I know
Can someone please explain why IE7 insists on putting a space between the table
Can someone please explain how you can write a url pattern and view that
can someone please help me. why does this return an error: Dim stuff As

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.