Android/Java - Clicking a image in a listview
<p>I made a listview in Android Studio. The listview has a image in every item but I don't know how to make it clickable. I did browse the internet for a solution but the hard part seems to be implementing it in my own code. I cannot figure that out.</p>

<p>Image in question = ex_img</p>

<p>-- Keep in mind when the image is clicked, it should also know its position in the list. </p>

<p>Thanks for reading and I hope you can help me out.</p>

<p>Adapter for list:</p>

<pre><code>public class CustomList extends ArrayAdapter&lt;String&gt; {
    private String[] ex_name;
    private String[] ex_diff;
    private String[] ex_muscle;
    private String[] ex_dpr;
    private Integer[] ex_img;
    private Activity context;

    public CustomList(Activity context, String[] ex_name, String[] ex_diff, String[] ex_muscle, String[] ex_dpr,
                      Integer[] ex_img) {
        super(context, R.layout.row_layout, ex_name);
        this.context = context;
        this.ex_name = ex_name;
        this.ex_muscle = ex_muscle;
        this.ex_diff = ex_diff;
        this.ex_dpr = ex_dpr;
        this.ex_img = ex_img;

    }
//LIST --&gt; XML
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        View listViewItem = inflater.inflate(R.layout.row_layout, null, true);
        TextView list_name = (TextView) listViewItem.findViewById(R.id.ex_name);
        TextView list_diff = (TextView) listViewItem.findViewById(R.id.ex_diff);
        TextView list_muscle = (TextView) listViewItem.findViewById(R.id.ex_muscle);
        ImageView list_image = (ImageView) listViewItem.findViewById(R.id.ex_img);
        TextView list_dpr = (TextView) listViewItem.findViewById(R.id.ex_dpr);

        list_name.setText(ex_name[position]);
        list_muscle.setText(ex_muscle[position]);
        list_diff.setText(ex_diff[position]);
        list_dpr.setText(ex_dpr[position]);
        list_image.setImageResource(ex_img[position]);

        return  listViewItem;

    }
}
</code></pre>

<p>Part from MainActivity that might be needed:</p>

<pre><code> private Integer img[] = {
            R.drawable.ic_favorite_white_24dp,
            R.drawable.ic_location_on_white_24dp,
            R.drawable.ic_update_white_24dp,
            R.drawable.ic_local_dining_white_24dp,
            R.drawable.ic_local_dining_white_24dp

    };


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

        CustomList customList = new CustomList(this, name, diff, muscle, dpr, img);

        listView = (ListView) findViewById(R.id.listview);
        listView.setAdapter(customList);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                Toast.makeText(getApplicationContext(),"You Clicked "+name[i],Toast.LENGTH_SHORT).show();
            }
        });
    }
</code></pre>