LarsWerkman / QuickReturnListView

A implementation of Roman Nurik's and Nick Butcher's Quick Return UI patern for a listview.
Apache License 2.0
698 stars 187 forks source link

Calling setAdaptor after generated #3

Open JamieHibbard opened 11 years ago

JamieHibbard commented 11 years ago

Great work,

However when I was calling, setAdaptor once it has computedY it was erroring.

I have a button that allows people to add a new row.

The way round i found was to reset all varibles within QuickReturnListView.java

public void reset() {

    mItemCount = 0;
    mItemOffsetY = null;
    scrollIsComputed = false;
    mHeight = 0;

}

and call it before using setadaptor. This then recalculates without having to reload.

Thought i'd post incase someone has another idea or it helps someone

zgzong commented 11 years ago

I suggest that overrides the setAdapter function, register data set observer, when observer the data set changed, reset parameters for computeScrollY.

@Override
public void setAdapter(ListAdapter adapter){
    super.setAdapter(adapter);
    adapter.registerDataSetObserver(new DataSetObserver(){
        public void onChanged() {
            reset();
          }
    });
}
tasomaniac commented 11 years ago

I am using Endless Adapter from Commons Guy. The dataset on my listadapter is changing lots of time when I scroll. Overriding setAdapter works for me but it makes the QuickReturnView flinging.

Nammari commented 10 years ago

@tasomaniac did you find any solution ??? i am facing the same problem as you . did you get rid of it ?

Zordid commented 10 years ago

Not only is setAdapter a problem: also on adapter.notifiyDataSetChanged() everything needs to be re-computed! Plus: iterating over ALL items in the list and invoke getView - that is practically a seriously bad idea. There's a reason that the ListView itself recycles views and never ever lets getView run for each and every item in the list at once!

Any thoughts on that?

tasomaniac commented 10 years ago

I think you have explained the real problem in a very good way.

Basically all the height of all the cells has to be computed. All of my rows have the same height. So I just get that height from the dimensions resource and make this for loop very fast and dynamic. On Mar 27, 2014 2:10 PM, "Zordid" notifications@github.com wrote:

Not only is setAdapter a problem: also on adapter.notifiyDataSetChanged() everything needs to be re-computed! Plus: iterating over ALL items in the list and invoke getView - that is practically a seriously bad idea. There's a reason that the ListView itself recycles views and never ever lets getView run for each and every item in the list at once!

Any thoughts on that?

Reply to this email directly or view it on GitHubhttps://github.com/LarsWerkman/QuickReturnListView/issues/3#issuecomment-38795109 .

Zordid commented 10 years ago

There are some other huge flaws inside the code as well: Why is getComputedScroll() assuming that there are ANY items? It just states

view = getChildAt(0) and accesses view.getTop() immediately without null-check...

This should not be advertised as a library... sorry.

mwong56 commented 10 years ago

@Zordid Yup, having the same problem as well. Don't think this is a library, just an example implementation. Does anyone know of an actual library that does the quick return ?

mwong56 commented 10 years ago

This library worked great for me

https://github.com/allminewuwei/QuickReturnView