Question: [![enter image description here](https://i.stack.imgur.com/s4Aaa.png)](https://i.stack.imgur.com/s4Aaa.png)

I am creating gallery using HorizontalScrollView, and I want to click the image in HorizontalScrollView.

Here is my code:

```
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK){
            if(data.getClipData() != null){
                int totalItemsSelected = data.getClipData().getItemCount();
                linearLayout = (LinearLayout) findViewById(R.id.linear);
                for(int i = 0; i < totalItemsSelected; i++){
                    Uri fileUri = data.getClipData().getItemAt(i).getUri();
                    ImageView image = new ImageView(this);
                    image.setAdjustViewBounds(true);
                    image.setImageURI(fileUri);
                    linearLayout.addView(image);
             }
        }
    }
}

```

Answer: 
Hi use the below code to `implement` click event to `ImageView`: 

```
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK){
        if(data.getClipData() != null){
            int totalItemsSelected = data.getClipData().getItemCount();
            linearLayout = (LinearLayout) findViewById(R.id.linear);
            for(int i = 0; i < totalItemsSelected; i++){
                Uri fileUri = data.getClipData().getItemAt(i).getUri();
                ImageView image = new ImageView(this);
                image.setAdjustViewBounds(true);
                image.setImageURI(fileUri);

                //click event
                image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Log.e(TAG,"Selected File URI : "+fileUri); 
                    }
                });

                linearLayout.addView(image);
            }
        }
    }
} 

```
**See below:**

```
for(int i = 0; i < totalItemsSelected; i++){
    Uri fileUri = data.getClipData().getItemAt(i).getUri();
    ImageView image = new ImageView(this);
    image.setAdjustViewBounds(true);
    image.setImageURI(fileUri);

    image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //what you want to do
        }
    });

    linearLayout.addView(image);
}

```