Apply setItemOnClickListener to Gridview Buttons. Kotlin or Java

Asked

Viewed 70 times

0

I made 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 I can trigger an Intent, knowing that you can only trigger an Intent inside an Activity. I can make the button work inside the Grid Adapter, but outside no.

  • 1

    Please paste the code so we can help you

1 answer

1

knowing that you can only trigger an Intent inside an Activity.

This is not true. It is possible anywhere as long as you have a Context available.

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

If you want to use Onitemclicklistener see this reply. It is explained why it does not work in this kind of case and how to make it work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.