why custom image view 's findviewbyId returns null
<p>Using this i can drag and zoom the imageview with in the screen by giving zoominglimits and boundaruy limits.But i want it for multiple images.For that i used the customview in the main.xml.But the problem is its findviewbyId returns null.What could be the problem? what am i missing here? Please help
PS:- im a 2months old android developer</p>

<pre><code> NewzoomlimitActivity .java

    public class NewzoomlimitActivity extends Activity
    {
        /** Called when the activity is first created. */
        int h, w;

        @Override
        public void onCreate( Bundle savedInstanceState )
        {
            super.onCreate( savedInstanceState );

            Display display = getWindowManager().getDefaultDisplay();
            h = display.getHeight();
            w = display.getWidth();

            CustomTouchImageView  img1 = new CustomTouchImageView( NewzoomlimitActivity.this);

            CustomTouchImageView  img11 = new CustomTouchImageView( NewzoomlimitActivity.this);

            CustomTouchImageView img = ( CustomTouchImageView ) findViewById(R.id.gIFView1  );

            Bitmap snoop = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher );

            if ( null == img )
            {
                Log.e( "img", "img is null" );
            }

            else
            {
                img.setImage( snoop, w, h );
            }

            //img1.setImage( snoop, w, h );
            //img11.setImage( snoop, w, h );
            img.setImage( snoop, w, h );
            //setContentView( img1 );
           // setContentView( img11 );
           setContentView( R.layout.main );

        }
    }

    main.xml
    ---------

     &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" &gt;

        &lt;TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" /&gt;

        &lt;LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" &gt;

            &lt;com.coders.vimek.CustomTouchImageView
                android:id="@+id/gIFView1"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_gravity="left" 
                android:src="@drawable/icon"
                /&gt;
               &lt;com.coders.vimek.CustomTouchImageView
                android:id="@+id/gIFView2"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_gravity="left" 
                android:src="@drawable/ic_launcher"
                /&gt;
        &lt;/LinearLayout&gt;

    &lt;/LinearLayout&gt;

    CustomTouchImageView .java
    -----------------------------
    public class CustomTouchImageView extends ImageView
    {

        private static final String TAG         = "Touch";
        Matrix                      matrix      = new Matrix();
        Matrix                      savedMatrix = new Matrix();

        // We can be in one of these 3 states
        static final int            NONE        = 0;
        static final int            DRAG        = 1;
        static final int            ZOOM        = 2;
        int                         mode        = NONE;

        int                         marg_left   = 80, marg_right = 80, marg_top = 100, marg_botom = 130, win_w, win_h;
        Bitmap                      bmp_picture;

        // Remember some things for zooming
        PointF                      start       = new PointF();
        PointF                      mid         = new PointF();
        float                       oldDist     = 1f;

        Context                     context;

        /*
         * public TouchImageView(Context context, AttributeSet attributeSet) {
         * super(context, attributeSet);
         * 
         * //TODO: }
         */

        public CustomTouchImageView( Context context )
        {
            super( context );
            super.setClickable( true );
            this.context = context;
            init();

        }

        public CustomTouchImageView( Context context, AttributeSet attrs )
        {
            super( context, attrs );
            super.setClickable( true );
            this.context = context;
            init();
            return;
        }

        public CustomTouchImageView( Context context, AttributeSet attrs, int defStyle )
        {
            super( context, attrs, defStyle );
            super.setClickable( true );
            this.context = context;
            init();
        }

        private void init()
        {
            matrix.setTranslate( 1f, 1f );
            setImageMatri(angry) matrix );
            setScaleType( ScaleType.MATRIX );

            setOnTouchListener( new OnTouchListener()
            {

                @Override
                public boolean onTouch( View v, MotionEvent rawEvent )
                {
                    WrapMotionEvent event = WrapMotionEvent.wrap( rawEvent );

                    // Dump touch event to log
                    // if (Viewer.isDebug == true){
                    // dumpEvent(event);
                    // }

                    // Handle touch events here...
                    switch ( event.getAction() &amp; MotionEvent.ACTION_MASK )
                    {
                    case MotionEvent.ACTION_DOWN:
                        savedMatrix.set( matrix );
                        start.set( event.getX(), event.getY() );
                        Log.d( TAG, "mode=DRAG" );
                        mode = DRAG;
                        break;
                    case MotionEvent.ACTION_POINTER_DOWN:
                        oldDist = spacing( event );
                        Log.d( TAG, "oldDist=" + oldDist );
                        if ( oldDist &gt; 10f )
                        {
                            savedMatrix.set( matrix );
                            midPoint( mid, event );
                            mode = ZOOM;
                            Log.d( TAG, "mode=ZOOM" );
                        }
                        break;
                    case MotionEvent.ACTION_UP:
                        int xDiff = ( int ) Math.abs( event.getX() - start.x );
                        int yDiff = ( int ) Math.abs( event.getY() - start.y );
                        if ( xDiff &lt; 8 &amp;&amp; yDiff &lt; 8 )
                        {
                            performClick();
                        }

                    case MotionEvent.ACTION_POINTER_UP:

                        // //////////////////////////////////////

                        // You need this first:

                        double max_zoom = 3,
                        min_zoom = 0.4;

                        float f[] = new float[ 9 ];
                        matrix.getValues( f );

                        if ( null == bmp_picture )
                        {
                            Log.e( "bmp_picture", "bmp is null" );
                        }
                        /*
                         * else if ( null == bmp_picture.getWidth() ) {} else if (
                         * null == bmp_picture ) {}
                         */
                        else
                        {
                            if ( f[ 0 ] &gt; max_zoom )
                            {
                                matrix.postScale( ( float ) max_zoom / f[ 0 ], ( float ) max_zoom / f[ 0 ], mid.x, mid.y );
                            }
                            if ( f[ 0 ] &lt; min_zoom )
                            {
                                matrix.postScale( ( float ) min_zoom / f[ 0 ], ( float ) min_zoom / f[ 0 ], mid.x, mid.y );
                            }

                            if ( -f[ 2 ] &gt; ( bmp_picture.getWidth() * f[ 0 ] - marg_left ) )
                            {
                                matrix.postTranslate( -( f[ 2 ] + bmp_picture.getWidth() * f[ 0 ] ) + marg_left, 0 );
                            }
                            if ( -f[ 5 ] &gt; ( bmp_picture.getHeight() * f[ 0 ] - marg_top ) )
                            {
                                matrix.postTranslate( 0, -( f[ 5 ] + bmp_picture.getHeight() * f[ 0 ] ) + marg_top );
                            }

                            if ( f[ 2 ] &gt; win_w - marg_right )
                            {
                                matrix.postTranslate( -( f[ 2 ] - win_w + marg_right ), 0 );
                            }

                            if ( f[ 5 ] &gt; win_h - marg_botom )
                            {
                                matrix.postTranslate( 0, -( f[ 5 ] - win_h + marg_botom ) );
                            }
                        }

                        // //////////////////////////////////////

                        mode = NONE;
                        Log.d( TAG, "mode=NONE" );
                        break;
                    case MotionEvent.ACTION_MOVE:
                        if ( mode == DRAG )
                        {
                            // ...
                            matrix.set( savedMatrix );
                            matrix.postTranslate( event.getX() - start.x, event.getY() - start.y );
                        }
                        else if ( mode == ZOOM )
                        {
                            float newDist = spacing( event );
                            Log.d( TAG, "newDist=" + newDist );
                            if ( newDist &gt; 10f )
                            {
                                matrix.set( savedMatrix );
                                float scale = newDist / oldDist;
                                matrix.postScale( scale, scale, mid.x, mid.y );
                            }
                        }
                        break;
                    }
                    setImageMatri(angry) matrix );
                    return true; // indicate event was handled
                }

            } );

        }

        public void setImage( Bitmap bm, int displayWidth, int displayHeight )
        {
            super.setImageBitmap( bm );
            Log.e( "win_w", "2" );
            bmp_picture = bm;

            win_h = displayHeight;
            win_w = displayWidth;
            Log.e( "win_h", String.valueOf( win_h ) );

            Log.e( "win_w", String.valueOf( win_w ) );

            float scale;
            if ( ( displayHeight / bm.getHeight() ) &gt;= ( displayWidth / bm.getWidth() ) )
            {
                scale = ( float ) displayWidth / ( float ) bm.getWidth();
            }
            else
            {
                scale = ( float ) displayHeight / ( float ) bm.getHeight();
            }

            savedMatrix.set( matrix );
            matrix.set( savedMatrix );
            matrix.postScale( scale, scale, mid.x, mid.y );
            setImageMatri(angry) matrix );
            // Center the image
            float redundantYSpace = ( float ) displayHeight - ( scale * ( float ) bm.getHeight() );
            float redundantXSpace = ( float ) displayWidth - ( scale * ( float ) bm.getWidth() );
            redundantYSpace /= ( float ) 2;
            redundantXSpace /= ( float ) 2;
            savedMatrix.set( matrix );
            matrix.set( savedMatrix );
            matrix.postTranslate( redundantXSpace, redundantYSpace );
            setImageMatri(angry) matrix );
        }

        /** Show an event in the LogCat view, for debugging */
        @SuppressWarnings( "unused" )
        private void dumpEvent( WrapMotionEvent event )
        {
            String names[] =
                { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" };
            StringBuilder sb = new StringBuilder();
            int action = event.getAction();
            int actionCode = action &amp; MotionEvent.ACTION_MASK;
            sb.append( "event ACTION_" ).append( names[ actionCode ] );
            if ( actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP )
            {
                sb.append( "(pid " ).append( action &gt;&gt; MotionEvent.ACTION_POINTER_ID_SHIFT );
                sb.append( ")" );
            }
            sb.append( "[" );
            for ( int i = 0; i &lt; event.getPointerCount(); i++ )
            {
                sb.append( "#" ).append( i );
                sb.append( "(pid " ).append( event.getPointerId( i ) );
                sb.append( ")=" ).append( ( int ) event.get(angry) i ) );
                sb.append( "," ).append( ( int ) event.getY( i ) );
                if ( i + 1 &lt; event.getPointerCount() )
                    sb.append( ";" );
            }
            sb.append( "]" );
            Log.d( TAG, sb.toString() );
        }

        /** Determine the space between the first two fingers */
        private float spacing( WrapMotionEvent event )
        {
            float x = event.get(angry) 0 ) - event.get(angry) 1 );
            float y = event.getY( 0 ) - event.getY( 1 );
            return FloatMath.sqrt( x * x + y * y );
        }

        /** Calculate the mid point of the first two fingers */
        private void midPoint( PointF point, WrapMotionEvent event )
        {
            float x = event.get(angry) 0 ) + event.get(angry) 1 );
            float y = event.getY( 0 ) + event.getY( 1 );
            point.set( x / 2, y / 2 );
        }

    }
</code></pre>
