Created
June 20, 2012 12:18
-
-
Save otarza/2959630 to your computer and use it in GitHub Desktop.
Pull To Refresh List View Example
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
package eu.erikw.pulltorefresh.sample; | |
import java.util.ArrayList; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.ViewGroup.LayoutParams; | |
import android.widget.ArrayAdapter; | |
import android.widget.LinearLayout; | |
import eu.erikw.PullToRefreshListView; | |
import eu.erikw.PullToRefreshListView.OnRefreshListener; | |
public class PullToRefreshListViewSampleActivity extends Activity { | |
private static ArrayList<String> items; | |
static{ | |
items = new ArrayList<String>(); | |
items.add("Ajax Amsterdam"); | |
items.add("Barcelona"); | |
items.add("Manchester United"); | |
items.add("Chelsea"); | |
items.add("Real Madrid"); | |
items.add("Bayern Munchen"); | |
items.add("Internationale"); | |
items.add("Valencia"); | |
items.add("Arsenal"); | |
items.add("AS Roma"); | |
items.add("Tottenham Hotspur"); | |
items.add("PSV"); | |
items.add("Olympique Lyon"); | |
items.add("AC Milan"); | |
items.add("Dortmund"); | |
items.add("Schalke 04"); | |
items.add("Twente"); | |
items.add("Porto"); | |
items.add("Juventus"); | |
} | |
private PullToRefreshListView listView; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
LinearLayout layout = new LinearLayout(this); | |
layout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); | |
setContentView(R.layout.main); | |
listView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview); | |
// Set the onRefreshListener on the list. You could also use | |
// listView.setOnRefreshListener(this); and let this Activity | |
// implement OnRefreshListener. | |
listView.setOnRefreshListener(new OnRefreshListener() { | |
@Override | |
public void onRefresh() { | |
// Your code to refresh the list contents goes here | |
// Make sure you call listView.onRefreshComplete() | |
// when the loading is done. This can be done from here or any | |
// other place, like on a broadcast receive from your loading | |
// service or the onPostExecute of your AsyncTask. | |
// For the sake of this sample, the code will pause here to | |
// force a delay when invoking the refresh | |
listView.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
listView.onRefreshComplete(); | |
} | |
}, 2000); | |
} | |
}); | |
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, items); | |
listView.setAdapter(adapter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment