Showing posts from December, 2012

Handler in Android

This Handler will hide the textview in a few seconds later.

public Handler ()

Since : API level 1

Default constructor associates this handler with the queue for the current thread. If there isn't one, this handler won't be able to receive messages.
Define a runnable variable with your code. Runnable hide = new Runnable() { @Override public void run() { // TODO Auto-generated method stub textview.setVisibility(View.INVISIBLE); } }; public final boolean postDelayed (Runnable r, long delayMillis)

Since: API Level 1


r                     The Runnable that will be executed.
delayMillis     The delay (in milliseconds) until the Runnable will be executed.


            Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the l…

Shared Preferences

The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).

To get a SharedPreferences object for your application, use one of two methods:
getSharedPreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.

getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name.

To write values:
Call edit() to get a SharedPreferences.Editor.
Add values with methods such as putBoolean() andputString().
Commit the new values with commit()
To read values, use SharedPreferences methods such as getBoolean() and getString().

To put values in Shared Pre…

Translate Animation

Translate Animation is used to move one object from one position to another position.

Signature is

public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

The coding for set animation for particular object is including 4 steps.

  1. Have to configure our object. If it is imageview means

ImageView img = (ImageView) findViewById(;
  2. Create animation.

TranslateAnimation moveLefttoRight = new TranslateAnimation(-1000, 0, 0, 0);   3. Then most important we should set time delay for that animation. Otherwise we cant get animation feel.
moveLefttoRight.setDuration(2000);   4. Set this animation to our object
img.startAnimation(moveLefttoRight);  Full coding for set animation for a object is
ImageView img = (ImageView) findViewById(; TranslateAnimation moveLefttoRight = new TranslateAnimation(-1000, 0, 0, 0); moveLefttoRight.setDuration(2000); moveLefttoRight.setFillAfter(true); img.startAnimation(moveLefttoRig…