-
Notifications
You must be signed in to change notification settings - Fork 6
/
SlipToPaddingRefresh.java
104 lines (94 loc) · 3.06 KB
/
SlipToPaddingRefresh.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.example.test;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
public class SlipToPaddingRefresh extends ListActivity implements OnScrollListener {
Aleph0 adapter = new Aleph0();
int lastItem = 0;
int mProgressStatus = 0;
private Handler mHandler = new Handler();
ProgressBar progressBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout searchLayout = new LinearLayout(this);
searchLayout.setOrientation(LinearLayout.HORIZONTAL);
progressBar = new ProgressBar(this);
progressBar.setPadding(0, 0, 15, 0);
searchLayout.addView(progressBar, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
TextView textView = new TextView(this);
textView.setText("加载中...");
textView.setGravity(Gravity.CENTER_VERTICAL);
searchLayout.addView(textView, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
searchLayout.setGravity(Gravity.CENTER);
LinearLayout loadingLayout = new LinearLayout(this);
loadingLayout.addView(searchLayout, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
loadingLayout.setGravity(Gravity.CENTER);
getListView().addFooterView(loadingLayout);
// Start lengthy operation in a background thread
// new Thread(new Runnable() {
// public void run() {
// while (mProgressStatus < 100) {
//
// // Update the progress bar
// mHandler.post(new Runnable() {
// public void run() {
// progressBar.setProgress(mProgressStatus);
// }
// });
// }
// }
// }).start();
registerForContextMenu(getListView());
setListAdapter(adapter);
getListView().setOnScrollListener(this);
}
public void onScroll(AbsListView v, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
lastItem = firstVisibleItem + visibleItemCount - 1;
System.out.println("lastItem:" + lastItem);
}
public void onScrollStateChanged(AbsListView v, int state) {
if (lastItem == adapter.count
&& state == OnScrollListener.SCROLL_STATE_IDLE) {
adapter.count += 10;
adapter.notifyDataSetChanged();
}
// if(state == OnScrollListener.SCROLL_STATE_IDLE ) {
// adapter.count += 10;
// adapter.notifyDataSetChanged();
// }
}
class Aleph0 extends BaseAdapter {
int count = 10;
public int getCount() {
return count;
}
public Object getItem(int pos) {
return pos;
}
public long getItemId(int pos) {
return pos;
}
public View getView(int pos, View v, ViewGroup p) {
TextView view = new TextView(SlipToPaddingRefresh.this);
view.setText("entry " + pos);
view.setHeight(90);
return view;
}
}
}