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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:47:18+00:00 2026-05-26T17:47:18+00:00

here is my code: public class MainMenuActivity extends Activity implements OnClickListener { public int

  • 0

here is my code:

public class MainMenuActivity extends Activity implements OnClickListener {

    public int width;
    public int height;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainmenu);

        Button play = (Button) findViewById(R.id.playbut);
        Button credits = (Button) findViewById(R.id.creditsbut);
        Button help = (Button) findViewById(R.id.helpbut);

        play.setOnClickListener(this);
        credits.setOnClickListener(this);
        help.setOnClickListener(this);

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        width = dm.widthPixels;
        height = dm.heightPixels;       
}

the problem is, public int width is not getting being set to dm.widthPixels and likewise for height. Any tips?

  • 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-26T17:47:19+00:00Added an answer on May 26, 2026 at 5:47 pm

    The code as given should result in the attributes being set. If it is not happening then there must be something else going on:

    • Maybe the method is not getting called.
    • Maybe the values of the dm pixel attributes are not what you expect them to be.
    • Maybe something else is changing the width and height values after the method call.
    • …
    • Maybe the code you are actually running doesn’t correspond to the source code that you’ve shown us … or the actual code that you are looking at. (For instance, you might have a problem with your build / deploy procedures.)

    If you are stumped, try running using a debugger, and setting a breakpoint in the method. Single step the method, and examine the actual values being set.

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

Sidebar

Related Questions

Here's the code: public class MenuTabActivity extends TabActivity implements OnTabChangeListener{ @Override protected void onCreate(Bundle
Here is the code: public class BillingService extends Service implements ServiceConnection { ... @Override
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
Here's the code: public class Exc { int x = 2; public void throwE(int
Here is the code: public class beautiful extends Activity { ImageView radar = (ImageView)
Spinner is not working. Here is my code: public class second extends Activity{ Spinner
Here's my code: public class Game extends JComponent implements Runnable { World w =
Here is a sample code: public class TestIO{ public static void main(String[] str){ TestIO
Here's the code: class qual { public static int fibonacci(int n) { if (n
I'm very new to Java. Here is my code: public class funk { int

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.