Create a clickable image in a GridView in Android

前端 未结 3 793
忘了有多久
忘了有多久 2020-12-09 12:06

I have images displayed in a GridView as in this tutorial. I want to be able to click on a single image and do other events and I need to know what image was clicked.

3条回答
  •  醉梦人生
    2020-12-09 12:38

    For a GridView you can use the setOnItemClickListener method to have an OnItemClickListener listener. That listener will give you a method that you must override with the signature

    onItemClick(AdapterView parent, View v, int position, long id)
    

    where you get the position of the item in the grid that was clicked and the View that is inside the cell of the grid. Is that what you need?

提交回复
热议问题