GithubHelp home page GithubHelp logo

Comments (4)

ncoolz avatar ncoolz commented on June 4, 2024

Ok, I will find the problem and fix it.

ps. If your app using this pull to refresh library is on google market, let me know your app if you do not mind. I want to add it into Apps page. Thanks.

from android-pull-to-refresh.

eunjae-lee avatar eunjae-lee commented on June 4, 2024

I'm just trying this library in my sample project. Thanks.

from android-pull-to-refresh.

ncoolz avatar ncoolz commented on June 4, 2024

I'm trying to resolve the problem. But it is hard to fix positions correct.

PullToRefreshListView adds a loading view on a header of a ListView as following code. After that, the ListView computes a position by including a number of headers.

// Create Loading Views ready for use later
FrameLayout frame = new FrameLayout(getContext());
mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a);
mHeaderLoadingView.setVisibility(View.GONE);
frame.addView(mHeaderLoadingView, lp);
mRefreshableView.addHeaderView(frame, null, false);

You can see a related issue in the link below.
ListView addHeaderView causes position to increase by one?

Of course, this issue can be resolved by overriding methods using a position parameter in ListView. But there are too many methods to be overrided. Also, I cannot defend side effects caused by overriding it.

So I recommend you to follow my suggestions listed below,

  1. Use the ListView.getItemAtPosition(position) instead of ListAdapter.getItem(position)
  2. If you have to get a correct position, create a decorator for OnItemClickListener like below.
class CorrectPositionOnItemClickListener implements OnItemClickListener {
    OnItemClickListener delegate;
    ListView listView;

    public CorrectPositionOnItemClickListener(OnItemClickListener delegate, ListView listView) {
        this.delegate = delegate;
        this.listView = listView;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view,
                    int position, long id) {
        // Convert a position to a index of a clicked item
        position -= listView.getHeaderViewsCount();
        delegate.onItemClick(adapterView, view, position, id);
    }};
}

...

mPullRefreshListView.setOnItemClickListener(new CorrectPositionOnItemClickListener(new OnItemClickListener() { 
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view,
                    int position, long id) {
        // Do something
    }

}, mPullRefreshListView));

...

NOTE : Don't use 1 and 2 together at once. If you use 1, you don't need to use 2.

I'm so confused to handle positions of items in ListView. It seems there is no consistent policy of that in it.

I'm sorry for not giving you a clearer way. I will give you if I come up with new idea.

from android-pull-to-refresh.

peacepassion avatar peacepassion commented on June 4, 2024

I use the last parameter long id in public void onItemClick(AdapterView<?> adapterView, View view,
int position, long id) as the position. It is OK so far.

from android-pull-to-refresh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.