Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position issue onClick when using headers #3

Closed
Fuhrmann opened this issue May 1, 2018 · 4 comments
Closed

Position issue onClick when using headers #3

Fuhrmann opened this issue May 1, 2018 · 4 comments

Comments

@Fuhrmann
Copy link

Fuhrmann commented May 1, 2018

Thanks again for helping me on the last issue. This is how I'm setting up the modal:

implementation 'com.github.Commit451:ModalBottomSheetDialogFragment:1.0.0'

my_modal_menu,xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/action_view"
        android:icon="@drawable/ic_view"
        android:title="View" />

    <item
        android:id="@+id/action_delete"
        android:icon="@drawable/ic_delete"
        android:title="Delete" />
</menu>

Then, I add a header to my modal and add the menu:

ModalBottomSheetDialogFragment.Builder()
    .add(R.menu.my_modal_menu)
    .header("Pick an option")
    .show(childFragmentManager, "my_modal")

The bottom modal shows up, but is throwing an throwIndexOutOfBoundsException

java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
        at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
        at java.util.ArrayList.get(ArrayList.java:308)
        at com.commit451.modalbottomsheetdialogfragment.ModalBottomSheetDialogFragment$Adapter$onCreateViewHolder$1.onClick(ModalBottomSheetDialogFragment.kt:212)

So I went and debugged and we got this:

When I'm pressing the second option on the bottom sheet modal, you get the adapterPosition which you can see below is 2.

studio64_2018-05-01_13-00-59

But the problem is I only have two options, position 0 and 1:

studio64_2018-05-01_13-01-07

Then the error is thrown. Maybe it has something to do to the fact I'm using a header so the adapterPosition is 2 because the header is 0?

Thanks!

@TJBlack31
Copy link
Contributor

I'm pretty sure I have this issue tackled. This is my first open-source contribution. Bear with me lol.

@TJBlack31
Copy link
Contributor

It's fixed and a new pull request has been added.

Thank you for the opportunity 👍

@Fuhrmann
Copy link
Author

Fuhrmann commented May 1, 2018

Nice! Good to know you fixed! Thanks for your contribution in the open source world! 😄

@Jawnnypoo
Copy link
Member

Fixed this as 1.0.1, thanks again @TJBlack31 for the fix and @Fuhrmann for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants