public class MainActivity extends Activity {
private SwipeRefreshLayout mSwipeRefreshLayout;
private ListView mListView;
private ArrayList<String> mList = new ArrayList<String>();
private ArrayAdapter<String> mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) this.findViewById(R.id.listview);
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, setData());
mListView.setAdapter(mAdapter);
mSwipeRefreshLayout = (SwipeRefreshLayout) this.findViewById(R.id.swiperefreshlayout);
mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (mSwipeRefreshLayout.isRefreshing()) {
mList.add("" + System.currentTimeMillis());
mAdapter.notifyDataSetChanged();
mSwipeRefreshLayout.setRefreshing(false);
}
}
}, 3000);
}
});
mSwipeRefreshLayout.setColorSchemeResources(
android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
}
private ArrayList<String> setData(){
this.mList.add("1111111");
this.mList.add("2222222");
return mList;
}
}