I just started working on android and I'm relatively new to the technology. I made 3 horizontal scrolls with drag and drop functionality and I want to drag and drop them in a certain area while keeping count of failed and successful drops. So far I accomplished everything but the code is not that effective and the approach I believe is not the best one. I want to know about a more efficient way to solve this problem. 

Part of my activity\_main.xml 

```
<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:onClick="onTouch">

        <ImageView
            android:id="@+id/b1"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a1"/>

        <ImageView
            android:id="@+id/b2"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a2"/>

        <ImageView
            android:id="@+id/b3"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a3"/>

        <ImageView
            android:id="@+id/b4"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a4"/>

        <ImageView
            android:id="@+id/b5"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a5"/>

        <ImageView
            android:id="@+id/b6"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a6"/>

        <ImageView
            android:id="@+id/b7"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a7"/>

        <ImageView
            android:id="@+id/b8"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a9"/>

        <ImageView
            android:id="@+id/b9"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a10"/>

        <ImageView
            android:id="@+id/b10"
            android:layout_width="200px"
            android:layout_height="200px"
            android:layout_gravity="center"
            android:layout_margin="20dp"
            android:src= "@drawable/a8"/>
    </LinearLayout>

</HorizontalScrollView>

```

and MainActivity.java

```
public class MainActivity extends Activity {

    int id;
    ImageView drag;
    LinearLayout drop;
    TextView text, success, fail;
    int total, failure, succ = 0, i;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        drag = (ImageView) findViewById(id);

        drag.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent arg1) {
                // TODO Auto-generated method stub
                ClipData data = ClipData.newPlainText("", "");
                View.DragShadowBuilder shadow = new View.DragShadowBuilder(drag);
                v.startDrag(data, shadow, null, 0);
                return false;
            }
        });

        drop = (LinearLayout) findViewById(R.id.bottomlinear);
        text = (TextView) findViewById(R.id.Total);
        success = (TextView) findViewById(R.id.Success);
        fail = (TextView) findViewById(R.id.Fail);

        drop.setOnDragListener(new View.OnDragListener() {

            @Override
            public boolean onDrag(View v, DragEvent event) {
                // TODO Auto-generated method stub
                final int action = event.getAction();
                switch (action) {

                    case DragEvent.ACTION_DRAG_STARTED:
                        break;

                    case DragEvent.ACTION_DRAG_EXITED:
                        break;

                    case DragEvent.ACTION_DRAG_ENTERED:
                        break;

                    case DragEvent.ACTION_DROP:
                        {
                            succ = succ + 1;
                            return (true);
                        }

                    case DragEvent.ACTION_DRAG_ENDED:
                        {
                            total = total + 1;
                            int failure = total - succ;
                            success.setText("Sucessful Drops :" + succ);
                            text.setText("Total Drops: " + total);
                            fail.setText("Failed Drops: " + failure);
                            return (true);

                        }

                    default:
                        break;
                }
                return true;
            }
        });
    }
}

```

The above code works for only first image view and I need a solution that enables all of them. I tried using ImageView array with for loop but that only returns the last ImageView. I would really appreciate some help with this.