Skip to main content

Posts

Showing posts from 2012

Featured post

Simple RecyclerView example with filter option in Android

Hi Guys, Maybe you all are expert in terms of using RecyclerView in android. This blog is simple example for using filter option with RecyclerView adapter. As for now you will instantiate RecyclerView and set the adapter to RecyclerView as following way. RecyclerView list = (RecyclerView) findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); list.setHasFixedSize(true); ArrayList&ltNumber&gt numbers = new ArrayList&lt&gt(); String ONEs[] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"}; String TENs[] = {"ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", "HUNDRED"}; String HUNDREDS[] = {"ZERO", "HUNDRED", "TWO HUND

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 Parameters r                      The Runnable that will be executed. delayMillis      The delay (in milliseconds) until the Runnable will be executed. Returns             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 wi

Simple example of Shared Preferences in Android

    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(). T

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(R.id.image);   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(R.id.player1image); TranslateAnimation moveLefttoRight = new TranslateAnimation(-1000, 0, 0, 0); moveLefttoRight.setDuration(2000); moveLefttoRight.setFillAfter(t