https://github.com/shontauro-zz/android-pulltorefresh-and-loadmore
android custom listview,with interaction pattern load more and pull to refresh to load data dinamically
https://github.com/shontauro-zz/android-pulltorefresh-and-loadmore
Last synced: 5 months ago
JSON representation
android custom listview,with interaction pattern load more and pull to refresh to load data dinamically
- Host: GitHub
- URL: https://github.com/shontauro-zz/android-pulltorefresh-and-loadmore
- Owner: shontauro-zz
- Created: 2012-01-23T01:52:58.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T06:07:43.000Z (over 4 years ago)
- Last Synced: 2023-10-25T20:29:59.387Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 495 KB
- Stars: 446
- Watchers: 43
- Forks: 195
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-android-ui - https://github.com/shontauro/android-pulltorefresh-and-loadmore
- awesome-android-ui - https://github.com/shontauro/android-pulltorefresh-and-loadmore
README
The first thing that i have to say is render thanks to johannilsson because
all the part of pull to refresh listview is based in the code of his repository
at .The target of this project is help other to apply the interaction pattern
pull to refresh and load more on an android listview.#Costum Load more listview for android
More information about load more interaction pattern
at#Costum Pull to refresh listview for android
More information about pull to refresh interaction pattern
atRepository at .
## Usage
### Layout for loadmore listview
``` xml
```
### Activity to LoadMoreListView``` java
// set a listener to be invoked when the list reaches the end
((LoadMoreListView) getListView())
.setOnLoadMoreListener(new OnLoadMoreListener() {
public void onLoadMore() {
// Do the work to load more items at the end of list here
new LoadDataTask().execute();
}
});private class LoadDataTask extends AsyncTask {
@Override
protected Void doInBackground(Void... params) {if (isCancelled()) {
return null;
}// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}for (int i = 0; i < mNames.length; i++)
mListItems.add(mNames[i]);return null;
}@Override
protected void onPostExecute(Void result) {
mListItems.add("Added after load more");// We need notify the adapter that the data have been changed
((BaseAdapter) getListAdapter()).notifyDataSetChanged();// Call onLoadMoreComplete when the LoadMore task, has finished
((LoadMoreListView) getListView()).onLoadMoreComplete();super.onPostExecute(result);
}@Override
protected void onCancelled() {
// Notify the loading more operation has finished
((LoadMoreListView) getListView()).onLoadMoreComplete();
}
}
```### Layout for pullandload listview
``` xml
```
### Activity to PullAndLoadListViewHere we have to pass two listeners one to pull operation and the other to load operation
``` java
// Set a listener to be invoked when the list should be refreshed.
((PullAndLoadListView) getListView())
.setOnRefreshListener(new OnRefreshListener() {public void onRefresh() {
// Do work to refresh the list here.
new PullToRefreshDataTask().execute();
}
});// set a listener to be invoked when the list reaches the end
((PullAndLoadListView) getListView())
.setOnLoadMoreListener(new OnLoadMoreListener() {
public void onLoadMore() {
// Do the work to load more items at the end of list
// here
new LoadMoreDataTask().execute();
}
});private class LoadMoreDataTask extends AsyncTask {
@Override
protected Void doInBackground(Void... params) {if (isCancelled()) {
return null;
}// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}for (int i = 0; i < mNames.length; i++)
mListItems.add(mNames[i]);return null;
}@Override
protected void onPostExecute(Void result) {
mListItems.add("Added after load more");// We need notify the adapter that the data have been changed
((BaseAdapter) getListAdapter()).notifyDataSetChanged();// Call onLoadMoreComplete when the LoadMore task, has finished
((PullAndLoadListView) getListView()).onLoadMoreComplete();super.onPostExecute(result);
}@Override
protected void onCancelled() {
// Notify the loading more operation has finished
((PullAndLoadListView) getListView()).onLoadMoreComplete();
}
}private class PullToRefreshDataTask extends AsyncTask {
@Override
protected Void doInBackground(Void... params) {if (isCancelled()) {
return null;
}// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}for (int i = 0; i < mAnimals.length; i++)
mListItems.addFirst(mAnimals[i]);return null;
}@Override
protected void onPostExecute(Void result) {
mListItems.addFirst("Added after pull to refresh");// We need notify the adapter that the data have been changed
((BaseAdapter) getListAdapter()).notifyDataSetChanged();// Call onLoadMoreComplete when the LoadMore task, has finished
((PullAndLoadListView) getListView()).onRefreshComplete();super.onPostExecute(result);
}@Override
protected void onCancelled() {
// Notify the loading more operation has finished
((PullAndLoadListView) getListView()).onLoadMoreComplete();
}
}
```### License
Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)Copyright (c) 2012 [Fabian Leon](http://yelamablog.blogspot.com/)