Comments (4)
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.
I'm just trying this library in my sample project. Thanks.
from android-pull-to-refresh.
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,
- Use the ListView.getItemAtPosition(position) instead of ListAdapter.getItem(position)
- 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.
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)
- add headerview HOT 2
- Unable to use Library in Eclipse HOT 2
- Customisation option request - don't display labels HOT 2
- Integration of StaggeredGridView HOT 1
- issue with viewpager fragment HOT 1
- Nullpointer on layout preview HOT 2
- How to get Scroll direction in Pull to refresh Scrollview HOT 1
- issue of height item. HOT 3
- Pull to refresh disappears if listview items is zero when pulled twice HOT 3
- please add RecyclerView support HOT 2
- How to center the default loading image?
- ScrollTo
- How to build Customization PullToRrefresh with ant HOT 2
- Save scroll position when refresh a listview
- PullToRefreshScrollView items not clickable while refreshing
- When the soft keyboard pops up, shake occur list HOT 4
- onPullUpToRefresh doesn't work inPullToRefreshListView
- Does it have RecyclerView support?
- FloatMath is deprecated
- Pull to left or right and show icon from left or right
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-pull-to-refresh.