AndroidViewflipper in Action

1 min read

Android View Flipper animates between two or more views that have been added to it. On request by the app it can flip between each child and shows only one child at a time.

Lets have a look at below pseudo code

mFlipper = (AdapterViewFlipper) inflater.inflate(R.layout.adapterviewfilpper, container, false);
mFlipper.setFlipInterval (3000);

setFlipInterval Method will be used to flip mFlipper with another child view after x seconds automatically.
setAutoStart , setFlipInterval methods can be called as per need of application developer. Many application developers may like to perform flipping after right / left swipe motion.

Just Like other Multiview containers like ListView , AdapterViewFlipper also takes a view adapter.

public class MyAdapterViewFlipper extends BaseAdapter{
private List mList;
private Context mContext;
public MyAdapterViewFlipper(List mList,Context context) {
this.mList = mList;
this.mContext = context;
public int getCount() {
return this.mList.size();
public Object getItem(int position) {
return mList.get(position);
public long getItemId(int position) {
return position;
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = null;
ViewHolder holder = null;
if(convertView == null) {
holder = new ViewHolder();
convertView = imageView = new ImageView(mContext);
holder.imgView = imageView;
} else {
holder = (ViewHolder)convertView.getTag();
Animation animation = null;
animation = AnimationUtils.loadAnimation(mContext,getAnimationFile(position));
return (View)imageView;
static class ViewHolder {
ImageView imgView;
int getAnimationFile(int position) {
int result=-1;
switch(position) {
case 0:
result = R.anim.from_left;
result = R.anim.fade_in;
return result;

Now at last but not the least override getView() method and start flipping child views.

Note : Dear Copy-Paste Community :).
Hope you are doing good.
If you are a software engineer study the material before copy pasting.

Else knowledge gets increased when it is shared.