I need your help on this. I am going to make an app using ViewPager and I since I never been programming for android before I thought it would be good to make a sample app first. I want to use the ViewPager a little bit differently than the classic list-of-items-style so I made an app that will show all the colors (or every 10th color) from #000000 to #FFFFFF.

It doesn't work. I've started the app on the emulator but I just get a white screen. If the default position of the ViewPager when starting is 0 then the color should be black. And when I try to make a breakpoint the program doesn't stop, or it's never reaching the point. I'm using eclipse.

These are the files of the project

MainActivity.java
-----------------

```
package com.example.colorswipe;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

public class MainActivity extends Activity {
    private ViewPager mPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mPager=(ViewPager)this.findViewById(R.id.pager);
        mPager.setAdapter(new MyAdapter());

    }

    private class MyAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return 0xFFFFFF/10;
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ColorView view=new ColorView(container.getContext());
            view.setBackgroundColor(android.graphics.Color.parseColor(String.format("#%06X", position*10)));
            view.setText(position);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View)object);
        }
    }
}

```

activity\_main.xml
------------------

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

    />
</LinearLayout>

```

ColorView.java
--------------

```
package com.example.colorswipe;

import android.content.Context;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ColorView extends LinearLayout {
    private TextView tv;
    public ColorView(Context context) {
        super(context);
        LayoutParams params=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        this.setLayoutParams(params);
        TextView tv=new TextView(context);
        this.tv=tv;
        this.addView(tv);
    }

    public void setText(int position) {
        tv.setText(Integer.toString(position).toCharArray(), 0, Integer.toString(position).length());
    }

}

```