I'm inflating a layout in a dialog, this layout shows many thumbnails of an eBook (96 ImageViews).
When I click on a certain ImageView it will take me to a certain page. The point is I'm having a 96 "if" statements so I want to make the code much more simpler. I'm asking for an advice or help to achieve this goal. Here is my code :

Thumbnails layout :

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#b8c9bc"
     android:weightSum="1"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/thumblayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="1"
        android:layout_weight="0.2"
        android:gravity="left"
        android:visibility="visible" >

               <ScrollView
                   android:id="@+id/ScrollView1"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_weight="0.9" >

                   <LinearLayout
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:orientation="vertical" >

                       <ImageView
                           android:id="@+id/imageView1"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_gravity="right"
                           android:src="@drawable/thumbpageh1" />

                       <ImageView
                           android:id="@+id/imageView2"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:src="@drawable/thumbpageh2" />

                       <ImageView
                           android:id="@+id/imageView3"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:src="@drawable/thumbpageh3" />

                       <ImageView
                           android:id="@+id/imageView4"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:src="@drawable/thumbpageh4" />

                       <ImageView
                           android:id="@+id/imageView5"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:src="@drawable/thumbpageh5" />

          .
          .
          .
          .
          .
          .
          .
          .

                            <ImageView
                           android:id="@+id/imageView101"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_gravity="left"
                           android:src="@drawable/thumbpageh97" />
                   </LinearLayout>

               </ScrollView>

                   <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/but"
        android:text="OK"
        android:textColor="#e2edd3"
        android:textSize="18sp"
        android:layout_weight="0.1"
        android:textStyle="bold" />

    </LinearLayout>

</LinearLayout> 

```

Java code :

```
       thumbbutton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            final Dialog dialog = new Dialog(context);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.thumblayout);

            WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();

            wmlp.gravity = Gravity.TOP | Gravity.LEFT;
            wmlp.x = 10;   //x position
            wmlp.y = 10;   //y position

            dialog.show();

   final Button cancel=(Button)dialog.findViewById(R.id.button1);
   final ImageView thumbpage1=(ImageView)dialog.findViewById(R.id.imageView1);
   final ImageView thumbpage2=(ImageView)dialog.findViewById(R.id.imageView2);
   final ImageView thumbpage3=(ImageView)dialog.findViewById(R.id.imageView3);
.
.
.
.
.
.
.
   final ImageView thumbpage96=(ImageView)dialog.findViewById(R.id.imageView100);
   final ImageView thumbpage97=(ImageView)dialog.findViewById(R.id.imageView101);

   cancel.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        dialog.hide();
    //   x=hsv.getScrollX();
    //     y=hsv.getScrollY();
        // Toast.makeText(getBaseContext(), "X="+String.valueOf(x)+" and Y="+String.valueOf(y), Toast.LENGTH_LONG).show();
    }
});

   thumbpage1.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        view1.setImageResource(R.drawable.page1);
        pagenumber=1;
        int p1=(pagenumber*2)-2;
        int p2=(pagenumber*2)-1;
        pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

          myDbHelper.openDataBase();
            checkMemoButtonStatus();
            myDbHelper.close();
    }
});

   thumbpage2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page2);
            pagenumber=2;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
            checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

   thumbpage3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page3);
            pagenumber=3;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
                checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

   thumbpage4.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page4);
            pagenumber=4;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
                checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

   thumbpage5.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page5);
            pagenumber=5;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
                checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

   thumbpage6.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page6);
            pagenumber=6;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
                checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

   thumbpage7.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page7);
            pagenumber=7;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
                checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

   thumbpage8.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page8);
            pagenumber=8;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
                checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

   thumbpage9.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page9);
            pagenumber=9;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

              myDbHelper.openDataBase();
                checkMemoButtonStatus();
                myDbHelper.close();
        }
    });

                .
                .
                .
                .
                .
                .
                .
                .
                .

   thumbpage96.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page96);
            pagenumber=96;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText(String.valueOf(p1)+" - "+String.valueOf(p2));

            myDbHelper.openDataBase();
            checkMemoButtonStatus();
            myDbHelper.close();
        }
    });
   thumbpage97.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            view1.setImageResource(R.drawable.page97);
            pagenumber=97;
            int p1=(pagenumber*2)-2;
            int p2=(pagenumber*2)-1;
            pages.setText("192");

            myDbHelper.openDataBase();
            checkMemoButtonStatus();
            myDbHelper.close();
        }
    }); 

//          visible++;
//          
//          if(visible==1)
//          {
//              thumblayout.setVisibility(View.VISIBLE);    
//              thumblayout.setVisibility(0);
//          }
//          else
//          {
//              thumblayout.setVisibility(View.GONE);   
//              visible=0;
//               
//          }

            // TODO Auto-generated method stub
        }
    });

```

I've searched about using a customized listview with images, also I've searched about getting the position of the view in the scrollview, but it didn't give much help, thank you