1
2
3
4
|
target=android-
8
android.library.reference.
1
=../Android-PullToRefresh/library
#android.library.reference.
2
=../Android-PullToRefresh/extras/PullToRefreshListFragment
#android.library.reference.
3
=../Android-PullToRefresh/extras/PullToRefreshViewPager
|
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
public
final
class
PullToRefreshListActivity
extends
ListActivity {
static
final
int
MENU_MANUAL_REFRESH =
0
;
static
final
int
MENU_DISABLE_SCROLL =
1
;
static
final
int
MENU_SET_MODE =
2
;
static
final
int
MENU_DEMO =
3
;
private
LinkedList<String> mListItems;
private
PullToRefreshListView mPullRefreshListView;
private
ArrayAdapter<String> mAdapter;
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_list);
mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
// Set a listener to be invoked when the list should be refreshed.
mPullRefreshListView.setOnRefreshListener(
new
OnRefreshListener<ListView>() {
@Override
public
void
onRefresh(PullToRefreshBase<ListView> refreshView) {
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
// Update the LastUpdatedLabel
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
// Do work to refresh the list here.
new
GetDataTask().execute();
}
});
// Add an end-of-list listener
mPullRefreshListView.setOnLastItemVisibleListener(
new
OnLastItemVisibleListener() {
@Override
public
void
onLastItemVisible() {
Toast.makeText(PullToRefreshListActivity.
this
,
"End of List!"
, Toast.LENGTH_SHORT).show();
}
});
ListView actualListView = mPullRefreshListView.getRefreshableView();
// Need to use the Actual ListView when registering for Context Menu
registerForContextMenu(actualListView);
mListItems =
new
LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));
mAdapter =
new
ArrayAdapter<String>(
this
, android.R.layout.simple_list_item_1, mListItems);
/**
* Add Sound Event Listener
*/
SoundPullEventListener<ListView> soundListener =
new
SoundPullEventListener<ListView>(
this
);
soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event);
soundListener.addSoundEvent(State.RESET, R.raw.reset_sound);
soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound);
mPullRefreshListView.setOnPullEventListener(soundListener);
// You can also just use setListAdapter(mAdapter) or
// mPullRefreshListView.setAdapter(mAdapter)
actualListView.setAdapter(mAdapter);
}
private
class
GetDataTask
extends
AsyncTask<Void, Void, String[]> {
@Override
protected
String[] doInBackground(Void... params) {
// Simulates a background job.
try
{
Thread.sleep(
4000
);
}
catch
(InterruptedException e) {
}
return
mStrings;
}
@Override
protected
void
onPostExecute(String[] result) {
mListItems.addFirst(
"Added after refresh..."
);
mAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshListView.onRefreshComplete();
super
.onPostExecute(result);
}
}
@Override
public
boolean
onCreateOptionsMenu(Menu menu) {
menu.add(
0
, MENU_MANUAL_REFRESH,
0
,
"Manual Refresh"
);
menu.add(
0
, MENU_DISABLE_SCROLL,
1
,
mPullRefreshListView.isScrollingWhileRefreshingEnabled() ?
"Disable Scrolling while Refreshing"
:
"Enable Scrolling while Refreshing"
);
menu.add(
0
, MENU_SET_MODE,
0
, mPullRefreshListView.getMode() == Mode.BOTH ?
"Change to MODE_PULL_DOWN"
:
"Change to MODE_PULL_BOTH"
);
menu.add(
0
, MENU_DEMO,
0
,
"Demo"
);
return
super
.onCreateOptionsMenu(menu);
}
@Override
public
void
onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle(
"Item: "
+ getListView().getItemAtPosition(info.position));
menu.add(
"Item 1"
);
menu.add(
"Item 2"
);
menu.add(
"Item 3"
);
menu.add(
"Item 4"
);
super
.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public
boolean
onPrepareOptionsMenu(Menu menu) {
MenuItem disableItem = menu.findItem(MENU_DISABLE_SCROLL);
disableItem
.setTitle(mPullRefreshListView.isScrollingWhileRefreshingEnabled() ?
"Disable Scrolling while Refreshing"
:
"Enable Scrolling while Refreshing"
);
MenuItem setModeItem = menu.findItem(MENU_SET_MODE);
setModeItem.setTitle(mPullRefreshListView.getMode() == Mode.BOTH ?
"Change to MODE_FROM_START"
:
"Change to MODE_PULL_BOTH"
);
return
super
.onPrepareOptionsMenu(menu);
}
@Override
public
boolean
onOptionsItemSelected(MenuItem item) {
switch
(item.getItemId()) {
case
MENU_MANUAL_REFRESH:
new
GetDataTask().execute();
mPullRefreshListView.setRefreshing(
false
);
break
;
case
MENU_DISABLE_SCROLL:
mPullRefreshListView.setScrollingWhileRefreshingEnabled(!mPullRefreshListView
.isScrollingWhileRefreshingEnabled());
break
;
case
MENU_SET_MODE:
mPullRefreshListView.setMode(mPullRefreshListView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START
: Mode.BOTH);
break
;
case
MENU_DEMO:
mPullRefreshListView.demo();
break
;
}
return
super
.onOptionsItemSelected(item);
}
private
String[] mStrings = {
"Abbaye de Belloc"
,
"Abbaye du Mont des Cats"
,
"Abertam"
,
"Abondance"
,
"Ackawi"
,
"Acorn"
,
"Adelost"
,
"Affidelice au Chablis"
,
"Afuega'l Pitu"
,
"Airag"
,
"Airedale"
,
"Aisy Cendre"
,
"Allgauer Emmentaler"
,
"Abbaye de Belloc"
,
"Abbaye du Mont des Cats"
,
"Abertam"
,
"Abondance"
,
"Ackawi"
,
"Acorn"
,
"Adelost"
,
"Affidelice au Chablis"
,
"Afuega'l Pitu"
,
"Airag"
,
"Airedale"
,
"Aisy Cendre"
,
"Allgauer Emmentaler"
};
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?
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"
>
<!-- The PullToRefreshListView replaces a standard ListView widget. -->
<
com.handmark.pulltorefresh.library.PullToRefreshListView
android:id
=
"@+id/pull_refresh_list"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:cacheColorHint
=
"#00000000"
android:divider
=
"#19000000"
android:dividerHeight
=
"4dp"
android:fadingEdge
=
"none"
android:fastScrollEnabled
=
"false"
android:footerDividersEnabled
=
"false"
android:headerDividersEnabled
=
"false"
android:smoothScrollbar
=
"true"
/>
</
LinearLayout
>
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
xmlns:tools
=
"http://schemas.android.com/tools"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
android:orientation
=
"vertical"
android:background
=
"@color/activity_white_bk"
>
<
include
layout
=
"@layout/titlebar_layout"
/>
<
com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr
=
"http://schemas.android.com/apk/res-auto"
ptr:ptrMode
=
"pullUpFromBottom"
ptr:ptrHeaderTextColor
=
"@color/silver_gray"
ptr:ptrHeaderSubTextColor
=
"@color/orange"
ptr:ptrDrawable
=
"@drawable/share_to_time_line_icon"
android:id
=
"@id/order_listview"
android:cacheColorHint
=
"@android:color/transparent"
android:descendantFocusability
=
"blocksDescendants"
android:divider
=
"@color/listitem_content_line"
android:dividerHeight
=
"0.5dip"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
/>
</
LinearLayout
>
|
1
2
|
//当前默认的滑动模式
private
Mode mDefaultMode;
|
1
2
|
//获取当前的模式
mDefaultMode=mListview.getMode();
|
1
2
3
|
//这样可以使滑动失效
mListview.setMode(Mode.DISABLED);
//如果需要重新刷新的话 我们可以通过之前保存的Mode对象,重新设置一下就OK
|