Using Pull to Refresh in Android we going to use external libraries i.e. “Android-PullToRefresh” , “ActionBar-PullToRefresh”. These libraries developed by Chrisbanes. Android-PullToRefresh is no longer maintained by Chrisbanes so we going to use ActionBar-PullTo Refresh .

This Library is also compatible with “ActionBarSherlock” and it wants minimun API Level 14 . It is also supported with Lower API Levels and I’ll update you later.Lets move on towards tutorial –

2). After importing to your eclipse IDE it will show some errors so you have to solve it but i have already saved your time guyz you just need to download my source code which is working so good and cool .

NOTE – SO, need not to download any libraries as above i mentioned ,you just need to download my source code and import it .

Here in my project i’have use four java files lets start with –

BaseActivity.java , This class will support all other Views like ListView,ScrollView,WebView. This Class will extend Activity Class and paste the below code in your Java File. BaseActivity.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

packageandroidarena.pulltorefreshexample;

import androidarena.pulltorefreshexample.R;

import android.app.Activity;

import android.app.Fragment;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.Toast;

publicclassBaseActivityextendsActivity{

@Override

protectedvoidonCreate(Bundle savedInstanceState){

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

// Add the Sample Fragment if there is one

Fragment sampleFragment=getSampleFragment();

if(sampleFragment!=null){

getFragmentManager().beginTransaction()

.replace(android.R.id.content,sampleFragment).commit();

}

}

@Override

publicbooleanonCreateOptionsMenu(Menu menu){

// TODO Auto-generated method stub

getMenuInflater().inflate(R.menu.base_menu,menu);

returnsuper.onCreateOptionsMenu(menu);

}

@Override

publicbooleanonOptionsItemSelected(MenuItem item){

// This method is for menu. This menu items will appear in all

//activities extends this class. I have use this menus to navigate

//between activities. You can change this code as you wish

//

switch(item.getItemId()){

caseR.id.action_listview:

Toast.makeText(this,"Pull to Refresh in ListView",Toast.LENGTH_SHORT).show();

Intenti=newIntent(this,ListViewActivity.class);

startActivity(i);

returntrue;

caseR.id.action_scrollview:

Toast.makeText(this,"Pull to Refresh in Scroll View",Toast.LENGTH_SHORT).show();

Intentx=newIntent(this,ScrollViewActivity.class);

startActivity(x);

returntrue;

caseR.id.action_webview:

Toast.makeText(this,"Pull to Refresh in Web View",Toast.LENGTH_SHORT).show();

Intentz=newIntent(this,WebViewActivity.class);

startActivity(z);

returntrue;

}

returnsuper.onOptionsItemSelected(item);

}

//This method will override by child class. Then base class can get the fragment

protectedFragment getSampleFragment(){

returnnull;

}

}

Now goto menu folder and create base_menu.xml . It is helpful for showing and hiding the views according to space .