Skip to main content

Posts

Basic view components TextView part -2

Watch this on YouTube

Basic view components TextView part -1

Watch this on YouTube Watch part -2

Getting current display orientation of android device

Watch this on YouTube In some situations we need to to know what is the current display orientation of the device. In this post i explain how to get the current orientation of an android device. In order to get the display orientation of the android device you need to first get the display information of the device.                                                                       For getting the current display info you need to get an object of WindowManager class using the  method   getWindowManager(). After getting it you need to obtain an object of Display class using the WindowManager object and getDefaultDisplay() method.                           WindowManager manager = getWindowManager();     ...

Control display orientation of an android device.

Watch this on YouTube In some cases you want to fix the display orientation for your app in landscape or portrait. In this post i will explain how to restrict the orientation of your app only in landscape or portrait mode. You can set the display orientation by using the following method setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); If you want to restrict the display orientation in portrait mode, then you can use the following. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Also you have to made some changes in the androidmanifest.xml file as follows.   <activity             android:name="com.orientationdemo.MainActivity"             android:label="@string/app_name"              android:screenOrientation="landscape" > MainActivity.java package com.orientationdemo; import android.os.Bundle;...

Registering events for views

Watch this on YouTube MainActivity.java package com.registerevent; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { Button b1, b2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.button1); b2 = (Button) findViewById(R.id.button2); b1.setOnClickListener(bListener); b2.setOnClickListener(bListener); } private OnClickListener bListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String label = ((Button)v).getText().toString(); Toast.makeText(getBaseContext(), "you click" +label, Toast.LENGTH_LONG).show(); } }; @Override public boolean onCreateOptionsMenu(Menu ...

Creating android activity programatically -3

Watch this on YouTube

Creating android activity programatically -2

Watch this on YouTube Watch part -3