Reputation: 286
I used the following piece of code in onCreate() method... But still it is displaying both messages while transists from landscape to protrait. Please help me to getrid of it..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WindowManager wm=getWindowManager();
Display dis=wm.getDefaultDisplay();
if(dis.getWidth()>dis.getHeight())
Toast.makeText(getBaseContext(), "Landscape", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getBaseContext(), "Portarit", Toast.LENGTH_SHORT).show();
}
Upvotes: 1
Views: 301
Reputation: 7161
use getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
instead; width and height of the screen are fixed when you ask the defaultDisplay(). Otherwise you could do with getResources().getDisplayMetrics().widthPixels
and getResources().getDisplayMetrics().heightPixels
.
Upvotes: 2