-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Jan 23, 2012
0 parents
commit c4a076d
Showing
35 changed files
with
1,643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.classpath | ||
.project | ||
.settings | ||
bin | ||
gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
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 <https://github.com/johannilsson/android-pulltorefresh>. | ||
|
||
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 | ||
![Screenshot](https://github.com/shontauro/android-pulltorefresh-and-loadmore/raw/master/loadmore.png) | ||
|
||
More information about load more interaction pattern | ||
at <http://www.androidpatterns.com/uap_pattern/dynamic-loading-of-a-list> | ||
|
||
#Costum Pull to refresh listview for android | ||
![Screenshot](https://github.com/shontauro/android-pulltorefresh-and-loadmore/raw/master/pulltorefresh.png) | ||
|
||
More information about pull to refresh interaction pattern | ||
at <http://www.androidpatterns.com/uap_pattern/pull-to-refresh-2> | ||
|
||
Repository at <https://github.com/shontauro/android-pulltorefresh-and-loadmore>. | ||
|
||
## Usage | ||
|
||
### Layout for loadmore listview | ||
|
||
``` xml | ||
<!-- We have to indicate that the listview is now a LoadMoreListView --> | ||
|
||
<com.costum.android.widget.LoadMoreListView | ||
android:id="@+id/android:list" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" /> | ||
``` | ||
### 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<Void, Void, Void> { | ||
|
||
@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 | ||
<!-- We have to indicate that the listview is now a PullAndLoadListView --> | ||
|
||
<com.costum.android.widget.PullAndLoadListView | ||
android:id="@+id/android:list" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" /> | ||
``` | ||
### Activity to PullAndLoadListView | ||
|
||
Here 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<Void, Void, Void> { | ||
|
||
@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<Void, Void, Void> { | ||
|
||
@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/) | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.android.widget.example" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk android:minSdkVersion="7" /> | ||
|
||
<application | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" > | ||
<activity android:name="Main" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".LoadMoreExampleActivity" | ||
android:label="@string/app_name" > | ||
</activity> | ||
<activity android:name=".PullAndLoadExampleActivity" > | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<lint> | ||
</lint> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-optimizationpasses 5 | ||
-dontusemixedcaseclassnames | ||
-dontskipnonpubliclibraryclasses | ||
-dontpreverify | ||
-verbose | ||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* | ||
|
||
-keep public class * extends android.app.Activity | ||
-keep public class * extends android.app.Application | ||
-keep public class * extends android.app.Service | ||
-keep public class * extends android.content.BroadcastReceiver | ||
-keep public class * extends android.content.ContentProvider | ||
-keep public class * extends android.app.backup.BackupAgentHelper | ||
-keep public class * extends android.preference.Preference | ||
-keep public class com.android.vending.licensing.ILicensingService | ||
|
||
-keepclasseswithmembernames class * { | ||
native <methods>; | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet); | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet, int); | ||
} | ||
|
||
-keepclassmembers class * extends android.app.Activity { | ||
public void *(android.view.View); | ||
} | ||
|
||
-keepclassmembers enum * { | ||
public static **[] values(); | ||
public static ** valueOf(java.lang.String); | ||
} | ||
|
||
-keep class * implements android.os.Parcelable { | ||
public static final android.os.Parcelable$Creator *; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system use, | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
|
||
# Project target. | ||
target=android-7 | ||
android.library.reference.1=../pulltorefresh-and-loadmore/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" > | ||
|
||
<Button | ||
android:id="@+id/button1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:text="LoadMoreListView" /> | ||
|
||
<Button | ||
android:id="@+id/button2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:text="PullToRefreshAndLoadMoreListView" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" > | ||
|
||
<!-- We have to indicate that the listview is now a PullAndLoadListView --> | ||
|
||
<com.costum.android.widget.PullAndLoadListView | ||
android:id="@+id/android:list" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="hello">Hello World, LoadMoreExampleActivity!</string> | ||
<string name="app_name">Loadmoreexample</string> | ||
|
||
</resources> |
Oops, something went wrong.