Apply setItemOnClickListener to Button GridView. Kotlin or Java

0

I've done a gridView of buttons, but when I use the setOnItemClickListener method to trigger the respective buttons, it does not work.

I want to use the buttons so that I can trigger an intent, knowing that you can only trigger an intent within an activity. I can make the button work inside the Grid Adapter, but not out.

    
asked by anonymous 16.10.2018 / 14:43

1 answer

1
  

Knowing that you can only trigger an intent within an activity.

That's not true. It is possible on any side, as long as it has a Context available.

If you want to implement the OnClickListener of each button in the Adapter, you only need to pass a Context in the constructor and use it to create Intent.

If you want to use OnItemClickListener see this response . It explains why it does not work in this type of case and how to make it work.

    
16.10.2018 / 14:51