4

I was looking at this posting: Get screen dimensions in pixels when I was trying to determine the size of the device's screen while in a fragment class. One answer was close to what I needed but the only code that ended up working for me was:

WindowManager wm = (WindowManager) getView().getContext().getSystemService(Context.WINDOW_SERVICE); 
Display screen = wm.getDefaultDisplay();  

whereupon I could then use getHeight(); or another non-deprecated term.

Community
  • 1
  • 1
thomas.cloud
  • 881
  • 13
  • 30
  • so what is the question? – Manfred Moser Mar 23 '12 at 23:24
  • @Manfred Moser: This question was about how to return the screen dimensions from within a fragment class of whatever device is using an application with this code(ie 320x480). If you have any suggestions about how to improve this question I can definitely clarify the wording. Thanks. – thomas.cloud Mar 26 '12 at 17:36
  • you are not supposed to edit the question to contain the answer... – Manfred Moser Mar 26 '12 at 19:46

1 Answers1

8

You questions contains the answer! Just use getActvity() as the context in the fragment.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • Dont post tutorials on stackoverflow as questions. Answer other questions and if you have tutorials.. post them on your blog. Basically read the FAQ. – Manfred Moser Mar 29 '12 at 00:04