Pages

Monday, August 29, 2011

Custom Joins in Hibernate Query Language

This example tries to elaborate and explain how to make customized joins in hibernate queries. I will also explain how to retrieve the data from the HQL into a custom bean.

I will not get into hibernate setup in this blog. I will discuss that in some later blog. For this example, I am assuming a working knowledge in hibernate from you guys.

My bean in which i need to retrieve the data is:

public class UserApplicationBean implements Serializable {

private Long id;
private long userId;
private String userName;
private Double appPrice;
private Boolean free;
private Boolean isActive;
private int industryId;
private String appDescription;
private String name;
private String appIcon;
private boolean isDeleted;
private boolean android;
private boolean blackberry;
private boolean ipad;
private boolean iphone;
private String submitStatus;
private Date submitDate;
private String firstCategory;
private String secondCategory;
//Getter setter follow
}

The columns in my bean are mapped to the User table in my database i.e. for each column in my db table, I have a corresponding column in my bean.

Now, lets look at the query.

SELECT new com.vibe.bean.UserApplicationBean(userApp.id, userApp.name,
userApp.appIcon, userApp.submitDate, userApp.firstCategory, user.firstName, user.lastName,
userAppVital.isFree, userAppVital.appPrice,
(
SELECT userApp.id
))
FROM UserApplication userApp, User user, UserApplicationAppVital userAppVital
WHERE userApp.user.id = user.id
AND userAppVital.userApplication.id = userApp.id
AND userApp.submitStatus =:submitStatus
AND userApp.isDeleted = false
AND userApp.iphone = true
ORDER BY userApp.submitDate DESC

In this query, I am making a simple join between three tables user, userApplication and userApplicationAppVital (Refer to the where clause in the query).

Now lets us see the Select part of the query:
"Select new com.vibe.bean.UserApplicationBean( ... )"

In this, I am directly creating a new object of my bean and giving the columns to be selected as its arguments(refer to the query). So how does hibernate handle such a query?

To understand this lets first understand how a normal query works in hibernate.
Lets take a query :

Select * from User;

Where user is a model bean mapped to the database table. User code would be something like this:

@Entity
@Table(name = "tb_user")
public class User implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String firstName;
private String lastName;
.
.
.
}

Now, when hibernate executes the above query, hibernate internally maps the model bean in the query with the database table, fires the query and retrieves the resultset.

Now, hibernate code iterates the result set returned from the database and for every record returned from the database, creates a new object of the model bean and populates the object with the values returned.
The object is then added to a List. After iterating the complete result set, hibernate returns a reference to the List created as result to the calling function.

I hope I am clear till now. We have seen how hibernate interprets a simple query.

Now, returning back to our original query, if we see the "Select" clause of the query, the query become self-explanatory. Lets discuss the query:

"Select new com.vibe.bean.UserApplicationBean( ... )"

In this query, we have directed hibernate to use a particular bean class for storing the values returned from the database. Using this syntax, we can direct hibernate to store the result in any bean object we may like. Also, if we just require some columns to be returned instead of all the columns in the table, this method is better suited as it is faster.

Now, there are couple more things we need to do before we can make our query to work. We need to define a custom constructor in our bean corresponding to the columns mentioned in the "Select" part of the query:

public UserApplicationBean(){}
public UserApplicationBean(Long id, String name, String appIcon, Date submitDate, String firstCategory, String firstName, String lastName, Boolean isFree, Double appPrice, String submitStatus)
{
this.id=id;
this.name=name;
this.appIcon=appIcon;
this.submitDate=submitDate;
this.firstCategory=firstCategory;
this.userName = firstName + " " + lastName;
this.free = isFree;
this.appPrice = appPrice;
this.submitStatus = submitStatus;
}

Here, I have made a constructor corresponding to the new directive in the query. Also, please note that, I have only used complex data types in the constructor signature. This is necessary otherwise hibernate will throw an error.

Now we are all set. Run this query like all your other queries. Hibernate will return you a list of objects of the bean specified in the query which you can directly use ahead.

This is my first blog so please bear with me :). Also, do post your questions in the comments and I will try to resolve your issues.

Thursday, August 18, 2011

Starting With Android – Tutorial 1

We will be presenting series of tutorial which will help you to start with android.

Setup environment for Development
> Android provide its own SDK for development, it's totally java based, if you are good in Core java than you are good to start with Android Development

> First of all you need to set up an IDE(Integrated Development environment) for development, all tutorial we will be sharing are build using Eclipse IDE with Android Plugin installed.

> Setup steps are very well demonstrated on android platform
    http://developer.android.com/sdk/installing.html

Terms to understand before we begin

 ADT -> Android Development Tools

 AVD -> Android Virtual Device - This is an emulator which you can configure as a model of actual device.

Understanding Basic Structure of Android Application.



Below listed are basic folders which you will be using while developing android application. Name of folder itself will tell you little about what that folder will going to contain.

Let's start with them one by one and see if what you thought is right or otherwise.

1)res -> This folder contains all the resources which will be used inside applications. There are different folders for different type of resources

a) drawable -> This will contain all the images which you will be using in your application.

b) layout -> This folder will contain xml files. These xml files actually define the layout of   different screens of our application. Android provides a facility to define your screen  design in xml.  We will discuss these files in our later tutorials in more details

 c) values -> This folder contains different files for different type of key value pairs, which you will be using in your application. These files help in moving various type of constants from java code to configurable xml files. These have various advantages also such as ii8n, re-usability and maintenance of constants  and many more to explore.
Values can be of type:
String
Dimensions
Colors etc.
     d) raw -> This folder will contain files other than images such as music files, video files and other supported files.

 2) src  -> This folder contain all your java code

 3) lib -> This folder contain all external api jars which you want to use in your applications

 4) gen -> This is also java folder which is automatically generated by android. It will create a R.java file which will have  mapping for all files under /res folder. You can read more about R file from
                     http://developer.android.com/reference/android/R.html

 5) AndroidManifest.xml  -> This is configurable file for android application, this files contains configurations such as
       a) Minimum SDK application will be running on
       b) Different Uses Permission Application required
       c) Starting Screen of application
       d) And many more to explore

I hope this tutorial will help you in starting with android. We will soon be releasing other tutorials of these series.

Please share your comments and ratings, these will help us in improving and reaching more and more people.
You can also mail us on info@iotasol.com, or follow us on twitter @iotasol

You can also visit our websites www.iotasol.com and www.iotadomains.com

Wednesday, August 10, 2011

2 Stubborns on ride - Coming events cast there shadow before - You can't loose untill you loose

Conversation below started as a normal conversation, but never knew when it became cold war.
It's on INDIA vs ENGLAND 3rd test match (2011).... India looses 7 wickets on just 100 and so and than suddenly Dhoni and praveen kumar holding the nerves down, which started this never ending conversation between 2 Stubborn IDIOTS.........

I hope you guys enjoy this......and also can keep it continued by leaving your most welcomed comments........
Have a deep breath, here we go :) :)

Rajinder Singh Gill: 92/5

Yashpal Singla: I KNOW :P

Yashpal Singla: this is something similar to last test match

Yashpal Singla: where england 9th  patnership took hold of india

Yashpal Singla: india is going on same track

Yashpal Singla: let's see how much they can do

Rajinder Singh Gill: Yeah! u r absolutely right but this team is team india not England

Yashpal Singla: and this game is cricket not chess

Yashpal Singla: anything can happen

Rajinder Singh Gill: Indian are to not determined to do such kind of stuff. they are bit lazy in these kind of situations or u can say
extremely nervous..

Yashpal Singla: 6

Yashpal Singla: excellent shot

Rajinder Singh Gill: don't worry , Dhoni is not one man army...

Yashpal Singla: anyone can become anytime

Yashpal Singla: u know i m getting one gut feeling

Yashpal Singla: india will win this match

Rajinder Singh Gill: this time india will lose his no 1 title, just wait and watch..

Yashpal Singla: lets a have a bet

Yashpal Singla: dhoni makes his fifty in style :D

Rajinder Singh Gill: That's for sure... NO doubt, On what basis u want to bet on?

Rajinder Singh Gill: Is it for treat!!

Yashpal Singla: anyway you like it to be

Yashpal Singla: i m betting on INDIA

Rajinder Singh Gill: done India will lose his title for sure......First time in the captaincy of Dhoni, India will loose the series...

Yashpal Singla: india will not loose this match

Yashpal Singla: i m not saying anything about series and stuff

Yashpal Singla: i m talking about this match

Yashpal Singla: and india will win this match

Rajinder Singh Gill: Ok bhaji!!!

Rajinder Singh Gill: India will loose this match

Yashpal Singla: let's see

Rajinder Singh Gill: Ok Sir!

Rajinder Singh Gill: Anything for u?

Yashpal Singla: Super 6

Rajinder Singh Gill: Sixes won't win match until match is one day..

Yashpal Singla: you haven't seen enough of test matches than

Yashpal Singla: every run count whatever form of game it is

Rajinder Singh Gill: Not in the case of tests, if u were true than draw percentage should reduce...

Rajinder Singh Gill: No doubt we are spectactors, we don't know enough enough abt game. but at some points we are very true, bcoz we
know our team...

Yashpal Singla: that's your belief

Rajinder Singh Gill: It's not belief, this time i am denying you on facts.

Yashpal Singla: you always do that

Yashpal Singla: mate

Yashpal Singla: :D

Rajinder Singh Gill: It's not necessary that everytime i would be wrong..

Yashpal Singla: i m not saying you to be wrong

Yashpal Singla: but you always contradict

Yashpal Singla: so 200 crossed

Yashpal Singla: our target was 150

Yashpal Singla: which was impossible for you than

Rajinder Singh Gill: No probs bhaji, I am not a astrologer to judge the exact scores, u were also at same stage like me..

Yashpal Singla: yes i agree

Yashpal Singla: in similar way you are not able to see india will loose for sure

Rajinder Singh Gill: There is a very popular saying, "Coming events cast there shadow before". u might be aware of..

Yashpal Singla: yes that

Yashpal Singla: 's why i said my gut feeling

Yashpal Singla: not yours :)

Yashpal Singla: which you contradicted very strongly

Rajinder Singh Gill: That was my feeling....

Yashpal Singla: no you havn't expressed it as feeling but as a fact

Rajinder Singh Gill: Remember I wrote something on the blog

Yashpal Singla: this time india will lose his no 1 title, just wait and watch..

Yashpal Singla: this is not feeling

Yashpal Singla: this is a fact

Yashpal Singla: check your words

Rajinder Singh Gill: The very first line, You can't force your ways on others bt u can influence them...

Yashpal Singla: i am not forcing them

Yashpal Singla: anyone can become anytime
                u know i m getting one gut feeling
                India will win this match

Rajinder Singh Gill: Thats what i am saying, I am just trying to influence

Yashpal Singla: check my words

Rajinder Singh Gill: it

Yashpal Singla: you are not influcing mate, you are acting otherwise

Yashpal Singla: i m influncing in this case

Rajinder Singh Gill: No bhaji, You fell in my trap thats why we are in a mess...

Yashpal Singla: in a trap again forcing on me your facts

Yashpal Singla: i never felt in any trap......just putting my  influences forward

Rajinder Singh Gill: Very Clever!!!!

Yashpal Singla: Now that's a influence

Yashpal Singla: and you influenced me in this case

Yashpal Singla: :)

Rajinder Singh Gill: Just   a matter of time, you know me quit clearly but not well enough

Yashpal Singla: THat time will tell, you havn't seen enough of me too

I hope you guys enjoyed it.......Let's not finish it here :) :)

Tuesday, August 9, 2011

Zoom Image on Double Tap in android

The code below shows how we can zoom image on double tap in anroid, it's custom view class which will help us to make zoom image effect in anroid

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.widget.FrameLayout.LayoutParams;

/**
 * Custom class to zoom image in android
 *
 * @author Yash@iotasol.com
 */
public class ZoomImageView extends View implements OnGestureListener {

    private static final int SCALING_FACTOR = 50;
    private final int LANDSCAPE = 1;
    private GestureDetector gestureDetector;
    private Drawable image = null;
    private int scalefactor = 0;
    private int orientation;
    private int zoomCtr = 0;
    private long lastTouchTime = 0;
    private int winX, winY, imageX, imageY, scrollX = 0, scrollY = 0, left,
    top, bottom, right;

    public ZoomImageView(Context context, int orientation) {
        super(context);
        setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT));
        this.orientation = orientation;
        gestureDetector = new GestureDetector(this);
    }

   
    public void setImage(Drawable bitmap, Activity activity) {
        image = bitmap;
        imageSetting(activity);
    }

    public void setImage(Bitmap bitmap, Activity activity) {
        image = new BitmapDrawable(bitmap).getCurrent();
        imageSetting(activity);
    }

    /**
     * Works in both landscape and potrait mode.
     */
    private void imageSetting(Activity activity) {
        scrollX = scrollY = 0;
        scalefactor = 0;
        imageX = winX = activity.getWindow().getWindowManager()
                .getDefaultDisplay().getWidth();
        imageY = winY = activity.getWindow().getWindowManager()
                .getDefaultDisplay().getHeight();
        if (orientation == LANDSCAPE) {
            imageX = 3 * imageY / 4;
        }
        calculatePos();
    }

    public void calculatePos() {
        int tempx, tempy;
        tempx = imageX + imageX * scalefactor / 100;
        tempy = imageY + imageY * scalefactor / 100;
        left = (winX - tempx) / 2;
        top = (winY - tempy) / 2;
        right = (winX + tempx) / 2;
        bottom = (winY + tempy) / 2;
        invalidate();
    }

   
    /**
     * Redraws the bitmap when zoomed or scrolled.
     */
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (image == null)
            return;

        image.setBounds(left + scrollX, top + scrollY, right + scrollX, bottom
                + scrollY);
        image.draw(canvas);
    }

    public void zoomIn() {
        scalefactor += SCALING_FACTOR;
        calculatePos();
    }

    public void zoomOut() {
        if (scalefactor == 0)
            return;
        scrollX = scrollY = 0;
        scalefactor -= SCALING_FACTOR;
        calculatePos();
    }

    public void scroll(int x, int y) {
        scrollX += x / 5;
        scrollY += y / 5;
        if (scrollX + left > 0) {
            scrollX = 0 - left;
        } else if (scrollX + right < winX) {
            scrollX = winX - right;
        }
        if (scrollY + top > 0) {
            scrollY = 0 - top;
        } else if (scrollY + bottom < winY) {
            scrollY = winY - bottom;
        }
        invalidate();
    }

    @Override
    public boolean onTouchEvent(MotionEvent me) {
        boolean onTouchEvent = gestureDetector.onTouchEvent(me);
        return onTouchEvent;
    }

    @Override
    public boolean onDown(MotionEvent arg0) {
        long thisTime = arg0.getEventTime();
        if (thisTime - lastTouchTime < 250) {
            lastTouchTime = -1;
            onDoubleTap();
            return true;
        }
        lastTouchTime = thisTime;
        return true;
    }
   
    @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                float distanceY) {
            if (zoomCtr == 0)
                return false;
            scroll((int) (e2.getX() - e1.getX()), (int) (e2.getY() - e1.getY()));
            return true;
        }
   
        private void onDoubleTap() {
            if (zoomCtr == 0) {
                zoomCtr++;
                zoomIn();
                return;
            }
            zoomCtr--;
            zoomOut();
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public void onLongPress(MotionEvent e) {
    }

   

    @Override
    public void onShowPress(MotionEvent e) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stub
        return true;
    }
}


Below is the test class which is used as example to run the ZoomImageView

import android.app.Activity;
import android.os.Bundle;

public class TestTapActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ZoomImageView imageView = new ZoomImageView(this, getWindow()
                .getWindowManager().getDefaultDisplay().getOrientation());
        imageView.setImage(this.getResources().getDrawable(R.drawable.sample1),
                this);

        this.setContentView(imageView);
    }
}


I hope this post will be helpful. 

Please share your comments and and you can also contact me @ info@iotasol.com or visit our site www.iotasol.com , www.iotadomains.com.


Friday, August 5, 2011

Extracting Zip File in Android

The code snippet below explains how to extract zip file in android
You can call extractZip method with activity from where its called and path of file to be extracted
It will extract the files on same destination path
/**
 * This method will extract the zip file from location inside application 
 * 
 * @param activity
 * @param destinationPath - Path of zip file
 * @param _location - location where file will be extracted
 * @author Yash@iotasol.com
 */
public void extractZip(Activity activity,String destinationPath,String _location ) {
System.out.println(" ctr : ::: extract zip" + zipExtracted + " : "
+ destinationPath);
FileInputStream fin = null;
ZipInputStream zin = null;
try {
fin = new FileInputStream(destinationPath);
zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
extractDirectoryZipEntry(ze.getName(), _location);
} else {
extractZipFileEntry(_location, zin, ze);
}
}
zipExtracted = true;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (zin != null) {
zin.close();
}
if (fin != null) {
fin.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}

}



/**
 * This method will work on every single zip entry and store it in location
 * Buffered input stream is used to speed up the downloading process
 * @param _location
 * @param zin
 * @param ze
 * @author Yash@iotasol.com
 */
private void extractZipFileEntry(String _location, ZipInputStream zin,
ZipEntry ze) {
System.out.println(">>>>> file : " + ze.getName());
FileOutputStream fout = null;
BufferedOutputStream bout = null;
try {
fout = new FileOutputStream(_location + ze.getName());
bout = new BufferedOutputStream(fout, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = zin.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
}
} catch (Exception r) {
r.printStackTrace();
} finally {
try {
zin.closeEntry();
if (bout != null)
bout.close();
if (fout != null)
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(">>>>> file downloaded: " + ze.getName());
}


/**
 * This method will work on every single zip entry in case if its a directory, and creates new
 * 
 * @param dir
 * @param _location
 * @author Yash@iotasol.com
 */
private void extractDirectoryZipEntry(String dir, String _location) {

File f = new File(_location + dir);

if (!f.isDirectory()) {
f.mkdirs();
}
}


I hope this post will be helpful. 

Please share your comments and and you can also contact me @ info@iotasol.com or visit our site www.iotasol.com , www.iotadomains.com.

Creating Custom Horizontal Scroll View With Snap or paging

I have faced various issues to develop a horizontal scroll view with paging effect. I googled it a lot but not able to find anything satisfactory. Some search results help me, using those i have created my own custom horizontal scrollview class which can give similar effect as effect on Tablet Home page.

I will be discussing it step by step so that you can use it where required and it becomes easy for you to understand.

Step 1) Layout file -  Simple layout file for demo


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_height="match_parent"
android:layout_width="match_parent" android:id="@+id/layer">
</LinearLayout>

Step 2) CustomHorizontalScrollView - Class file which extends HorizontalScrollView and give snapping or paging effect.


public class CustomHorizontalScrollView extends HorizontalScrollView implements
OnTouchListener, OnGestureListener {

        private static final int SWIPE_MIN_DISTANCE = 300;

private static final int SWIPE_THRESHOLD_VELOCITY = 300;
private static final int SWIPE_PAGE_ON_FACTOR = 10;


private GestureDetector gestureDetector;
private int scrollTo = 0;
private int maxItem = 0;
private int activeItem = 0;
private float prevScrollX = 0;
private boolean start = true;
private int itemWidth = 0;
private float currentScrollX;
private boolean flingDisable = true;

public CustomHorizontalScrollView(Context context) {
super(context);
setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
}

public CustomHorizontalScrollView(Context context, int maxItem,
int itemWidth) {
this(context);
this.maxItem = maxItem;
this.itemWidth = itemWidth;
gestureDetector = new GestureDetector(this);
this.setOnTouchListener(this);
}

@Override
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
Boolean returnValue = gestureDetector.onTouchEvent(event);

int x = (int) event.getRawX();

switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
if (start) {
this.prevScrollX = x;
start = false;
}
break;
case MotionEvent.ACTION_UP:
start = true;
this.currentScrollX = x;
int minFactor = itemWidth
/ ConfigurationParams.SWIPE_PAGE_ON_FACTOR;

if ((this.prevScrollX - this.currentScrollX) > minFactor) {
if (activeItem < maxItem - 1)
activeItem = activeItem + 1;

} else if ((this.currentScrollX - this.prevScrollX) > minFactor) {
if (activeItem > 0)
activeItem = activeItem - 1;
}
System.out.println("horizontal : " + activeItem);
scrollTo = activeItem * itemWidth;
this.smoothScrollTo(scrollTo, 0);
returnValue = true;
break;
}
return returnValue;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (flingDisable)
return false;
boolean returnValue = false;
float ptx1 = 0, ptx2 = 0;
if (e1 == null || e2 == null)
return false;
ptx1 = e1.getX();
ptx2 = e2.getX();
// right to left

if (ptx1 - ptx2 > ConfigurationParams.SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > ConfigurationParams.SWIPE_THRESHOLD_VELOCITY) {
if (activeItem < maxItem - 1)
activeItem = activeItem + 1;

returnValue = true;

} else if (ptx2 - ptx1 > ConfigurationParams.SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > ConfigurationParams.SWIPE_THRESHOLD_VELOCITY) {
if (activeItem > 0)
activeItem = activeItem - 1;

returnValue = true;
}
scrollTo = activeItem * itemWidth;
this.smoothScrollTo(0, scrollTo);
return returnValue;
}

@Override
public boolean onDown(MotionEvent e) {
return false;
}

@Override
public void onLongPress(MotionEvent e) {
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
return false;
}

@Override
public void onShowPress(MotionEvent e) {
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
}



Step 3) TestHorizontalActivity- This class will be used as test class


public class TestHorizontalActivity extends Activity {

private LinearLayout linearLayout;
private CustomHorizontalScrollView horizontalScrollView;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
horizontalScrollView = new CustomHorizontalScrollView(this, 3,
width);
setContentView(R.layout.horizontal);
linearLayout = (LinearLayout) findViewById(R.id.layer);
linearLayout.addView(horizontalScrollView);

LinearLayout container = new LinearLayout(this);
container.setLayoutParams(new LayoutParams(width, height));
// container.setHeight(height);

TextView textView = new TextView(this);
textView.setWidth(width);
textView.setHeight(height);
textView.setGravity(Gravity.CENTER);
textView.setText("First  Screen");
textView.setBackgroundColor(Color.CYAN);
container.addView(textView);

textView = new TextView(this);
textView.setWidth(width);
textView.setHeight(height);
textView.setGravity(Gravity.CENTER);
textView.setText("Second  Screen");
textView.setBackgroundColor(Color.GREEN);
container.addView(textView);

textView = new TextView(this);
textView.setWidth(width);
textView.setHeight(height);
textView.setGravity(Gravity.CENTER);
textView.setText("Third  Screen");
textView.setBackgroundColor(Color.RED);
container.addView(textView);

horizontalScrollView.addView(container);
}

}


This is it, these 3 simple steps and you are ready to run a paging effect in your android application.

In next blog i will discuss how we can use combination of both horizontal scrolling and vertical scrolling.


I hope this post will be helpful. 

Please share your comments and and you can also contact me @ info@iotasol.com or visit our site www.iotasol.com , www.iotadomains.com.