Skip to main content

Posts

Showing posts from May, 2013

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();           Display disp = manager.getDefaultDisplay(); MainActivity.java package com.orientationdemo; import android.os.Bundle; import android.app.Activity; import android.view.Display; import android.view.Menu; import android.view.WindowManager; import a

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; import android.app.Activity; import android.content.pm.ActivityInfo; import andr

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

Creating android activity programatically

Watch this on YouTube   Watch part -2 In android an activity can be created in two ways, first one is simply using the android xml file in the layout folder of your android project and another ways is to create all these views and view groups for the activity by writing programs or code. So in this post i explain how to create an android layout dynamically. I explain it using the following example. please watch the above video for getting more information about this. MainActivity.java package com.programlayout; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView (R.layout.activity_main); android.widget.LinearLayout.LayoutPar

Enhanced for loop in java -2

Watch this on YouTube

Enhanced for loop in java

Watch this on YouTube Watch part -2 Enhanced for loop or the for each loop is a special purpose for loop used for working with arrays in java. Syntax:                  for ( type variable : array_name )                  {                  statement / statements ;                  }                 class ForEachDemo { public static void main(String args[]) { for(String data : args) { System.out.println(data); } } }

Nested for loop -2

Watch this on YouTube

Nested for loop

Watch this on YouTube Watch part -2 A loop inside another loop is called the nesting of loops. So a for loop inside the body of another for loop is called a nested for loop. Nesting of for loop are essential for handling multidimensional arrays. Also nested for loop are needed for handling table of contents (rows & columns).    Syntax of a Nested for loop:                                                            for ( initialization ; condition ; updating)                                                         { // Starting of outer loop                                                                                                                for ( initialization ; condition ; updating)                                                         { // Starting of inner loop                                                          Statement / Statements ;                                                                                                  

Multiplication table of a number using for loop

Watch this on YouTube

java for loop part -2

Watch this on YouTube

java for loop

Watch this on YouTube for loop in java is one of the most important control statement in java. Java for loop syntax: for (initialization ; condition ; updating) { statement / statements; } Initialization perform only once at the starting of the loop. It is also possible to initialize more than one variable at the same time but separates them with comma operator. (int i = 0, j = 1 ;)  Condition is always a Boolean statement. If more than one condition present, then separates them with any of logical operators.  Updating is generally an increment / decrements (++ / --) statement. First perform initialization and check the condition, if the condition is true then the loop body executes and then perform updating. Again check the condition, and if it is true again executes the loop body. This will continues till the condition become false. for loop example in java: import java.io.*; class ForDemo { public static void main(String args[])throws IOException { Buf

Activities with same intent filter name part -2

Watch this on YouTube

Activities with same intent filter name

Watch this on YouTube View part 2 We already learn that, an intent filter is necessary for invoking an activity using intent object. Assume that  there is more than one activities present with same intent filter name. In this post i am going to explain this situation with a complete working example. If there is more than one activities with same intent filter name, than the android system will show a dialog window that prompt you to choose an appropriate activity to complete the action.    In this example there are two activities SecondActivity and ThirdActivity with same intent filter name as "common_filter". The manifest code segment for this activities are shown bellow.  1: <activity 2: android:name="com.testdemo.SecondActivity" 3: android:label="@string/title_activity_second" > 4: <intent-filter> 5: < action android:name="common_filter" /> 6: <category android:name="android.intent.c

while loop part -2

Watch this on YouTube

while loop part -1

Watch this on YouTube

if else if part -2

Watch this on YouTube

if else if part -1

Watch this on YouTube

if else part -2

Watch This On YouTube

if else part -1

Watch this in YouTube

Watching YouTube Videos in HD quality.

Sony Xperia ion HD Recording Demo

Display notifications in android -5

Watch this on YouTube