JimiSmith / PinnedHeaderListView

A ListView with pinned section headers for Android
663 stars 306 forks source link

Item can be selected if they are hidden behind a header #6

Open bmarty opened 11 years ago

bmarty commented 11 years ago

Hello,

I'm using your amazing PinnedHeaderListView for my project, and I encountered this issue: when scrolling, item are displayed behind the pinned header, which is what I expects, but if I click on the header, then the item behind is selected. I wnat this to have no effect.

Do you have the same behavior on your project?

I've added this in my SectionedBaseAdapter class to avoid selection of header: @Override public boolean isEnabled(int position) { return !isSectionHeader(position); }

But even without this function the issue is observed.

Moreover, I observed a secondary issue (but less critical for my project): The first header is not clickable. That is onSectionClick function is never called for him. I've not investigated this issue.

After having looking for a solution without success, I ask for an idea here.

Any way thank you for sharing your component.

bma

JimiSmith commented 11 years ago

Hi

I've noticed this behaviour myself - I'm hoping to get some time later this week to fix it

bmarty commented 11 years ago

Hello,

I've made a quite ugly fix for the issue. I've added setOnTouchListener(this); in the PinnedHedaerListView constructor and this method:

    /**
     * OnTouchListener interface
     */
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // Ignore touch event on the current header, else the hidden item
        // can be selected.
        if (mCurrentHeader == null) {
            return false;
        }

        // Consume event if it is on the current header
        if (event.getY() < mCurrentHeader.getHeight()) {
            return true;
        }

        return false;
    }

Note that it can also fix the click issue, but is also disable the scroll on this region...

Maybe it can be improved to solve the issue "The first header is not clickable".

BR

JimiSmith commented 11 years ago

That's similar to what I was thinking of doing - except I was thinking of doing it in [performItemClick](http://developer.android.com/reference/android/widget/AdapterView.html#performItemClick(android.view.View, int, long)) or performClick.

That should solve the issue of scrolling not working in that region.

I haven't tested that out at all though, so it it may not work.

bmarty commented 11 years ago

Your solution looks better :-). However, how will you get the coordinate of the touched area?

dannysunyu commented 11 years ago

My issue is similar to bmarty except I want the section header to be clickable instead of the items when they are behind that section header.

JimiSmith commented 11 years ago

Yes, this bug report is about making the section header clickable

JimiSmith commented 11 years ago

I've pushed a commit to the dev branch which should prevent the list items from getting the click events. The section header should receive touch events as well, but I haven't tested this fully

dannysunyu commented 11 years ago

I owe you a big thank, Jimi. Recently I am working on an app that requires this pinned header feature and I found flaws with your library. But after reporting to you, you come to my rescue in time. I try out the demo now and it appears to resolve the issue. But I am going to make a further examination. Hope this time it works!

jacobtabak commented 10 years ago

Looks like there is still an issue with section headers receiving click events. They receive touch events unless they are the "current header" in which case they don't receive click events.

Also, if a non-header item is a layout and has clickable items in it, they can still receive touch events from behind the header view.

varunbadgujar commented 10 years ago

Issue is still active please provide a solution we all are waiting for this.

jacobtabak commented 10 years ago

@varunbadgujar can you try adding an onclicklistener to the header view that doesn't do anything?

varunbadgujar commented 10 years ago

@jacobtabak i did try this but its not working its taking touch of behind the header view. @jacobtabak have you resolved this issue at your end ?

jacobtabak commented 10 years ago

@varunbadgujar no, I just saw your comment and thought it may be worth a shot. sorry to get your hopes up.

varunbadgujar commented 10 years ago

@JimiSmith any update for resolve this issue ?

huluwa-dev commented 10 years ago

@JimiSmith Hi, have you resolved this issue??