Skip to content

Commit 41a7524

Browse files
author
Chris Banes
committed
Add Sample Horizontal ScrollView Activity
1 parent 88452fb commit 41a7524

4 files changed

Lines changed: 109 additions & 2 deletions

File tree

sample/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
android:name=".PullToRefreshScrollViewActivity"
4747
android:label="PtR ScrollView" >
4848
</activity>
49+
<activity
50+
android:name=".PullToRefreshHorizontalScrollViewActivity"
51+
android:label="PtR HorizontalScrollView" >
52+
</activity>
4953
<activity
5054
android:name=".PullToRefreshWebView2Activity"
5155
android:label="PtR WebView Advanced" >
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical" >
6+
7+
<!-- The PullToRefreshScrollView replaces a standard PullToRefreshScrollView widget. -->
8+
9+
<com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView
10+
xmlns:ptr="http://schemas.android.com/apk/res-auto"
11+
android:id="@+id/pull_refresh_horizontalscrollview"
12+
android:layout_width="fill_parent"
13+
android:layout_height="fill_parent"
14+
ptr:ptrAnimationStyle="flip"
15+
ptr:ptrMode="both" >
16+
17+
<TextView
18+
android:layout_width="wrap_content"
19+
android:layout_height="fill_parent"
20+
android:padding="8dp"
21+
android:text="@string/filler_text"
22+
android:textSize="16sp" />
23+
</com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView>
24+
25+
</LinearLayout>

sample/src/com/handmark/pulltorefresh/samples/LauncherActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*******************************************************************************/
1616
package com.handmark.pulltorefresh.samples;
1717

18+
import com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView;
19+
1820
import android.app.ListActivity;
1921
import android.content.Intent;
2022
import android.os.Bundle;
@@ -25,7 +27,7 @@
2527
public class LauncherActivity extends ListActivity {
2628

2729
public static final String[] options = { "ListView", "ExpandableListView", "GridView", "WebView", "ScrollView",
28-
"ListView Fragment", "WebView Advanced" };
30+
"Horizontal ScrollView", "ListView Fragment", "WebView Advanced" };
2931

3032
@Override
3133
protected void onCreate(Bundle savedInstanceState) {
@@ -55,9 +57,12 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
5557
intent = new Intent(this, PullToRefreshScrollViewActivity.class);
5658
break;
5759
case 5:
58-
intent = new Intent(this, PullToRefreshListFragmentActivity.class);
60+
intent = new Intent(this, PullToRefreshHorizontalScrollViewActivity.class);
5961
break;
6062
case 6:
63+
intent = new Intent(this, PullToRefreshListFragmentActivity.class);
64+
break;
65+
case 7:
6166
intent = new Intent(this, PullToRefreshWebView2Activity.class);
6267
break;
6368
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*******************************************************************************
2+
* Copyright 2011, 2012 Chris Banes.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
package com.handmark.pulltorefresh.samples;
17+
18+
import android.app.Activity;
19+
import android.os.AsyncTask;
20+
import android.os.Bundle;
21+
import android.widget.HorizontalScrollView;
22+
23+
import com.handmark.pulltorefresh.library.PullToRefreshBase;
24+
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
25+
import com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView;
26+
27+
public final class PullToRefreshHorizontalScrollViewActivity extends Activity {
28+
29+
PullToRefreshHorizontalScrollView mPullRefreshScrollView;
30+
HorizontalScrollView mScrollView;
31+
32+
/** Called when the activity is first created. */
33+
@Override
34+
public void onCreate(Bundle savedInstanceState) {
35+
super.onCreate(savedInstanceState);
36+
setContentView(R.layout.activity_ptr_horizontalscrollview);
37+
38+
mPullRefreshScrollView = (PullToRefreshHorizontalScrollView) findViewById(R.id.pull_refresh_horizontalscrollview);
39+
mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener<HorizontalScrollView>() {
40+
41+
@Override
42+
public void onRefresh(PullToRefreshBase<HorizontalScrollView> refreshView) {
43+
new GetDataTask().execute();
44+
}
45+
});
46+
47+
mScrollView = mPullRefreshScrollView.getRefreshableView();
48+
}
49+
50+
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
51+
52+
@Override
53+
protected String[] doInBackground(Void... params) {
54+
// Simulates a background job.
55+
try {
56+
Thread.sleep(4000);
57+
} catch (InterruptedException e) {
58+
}
59+
return null;
60+
}
61+
62+
@Override
63+
protected void onPostExecute(String[] result) {
64+
// Do some stuff here
65+
66+
// Call onRefreshComplete when the list has been refreshed.
67+
mPullRefreshScrollView.onRefreshComplete();
68+
69+
super.onPostExecute(result);
70+
}
71+
}
72+
73+
}

0 commit comments

Comments
 (0)