main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Main activity
private SwipeRefreshLayout swipeRefreshLayout;
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getCountries());
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
handler.post(refreshing);
}
});
swipeRefreshLayout.setColorScheme(R.color.blue_bright, R.color.green_light,
R.color.orange_light, R.color.red_light);
}
private final Runnable refreshing = new Runnable(){
public void run(){
try {
if(isRefreshing()){
handler.postDelayed(this, 1000);
}else{
swipeRefreshLayout.setRefreshing(false);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
};
Add latest support_v4 library library files
Thank you
ReplyDelete