Skip to content

Instantly share code, notes, and snippets.

@nein37
Created August 6, 2014 04:36
Show Gist options
  • Save nein37/56d99b3d26dbc1ed5821 to your computer and use it in GitHub Desktop.
Save nein37/56d99b3d26dbc1ed5821 to your computer and use it in GitHub Desktop.
SwipeRefreshLayout覚え書き ref: http://qiita.com/nein37/items/c9ae7c8e3489b1276c14
public class RefreshFragment extends Fragment implements
SwipeRefreshLayout.OnRefreshListener {
private SwipeRefreshLayout mSwipeRefreshLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.refreshlayout, null);
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipelayout);
// 色設定
mSwipeRefreshLayout.setColorSchemeResources(R.color.red,
R.color.green, R.color.blue,
R.color.orange);
// Listenerをセット
mSwipeRefreshLayout.setOnRefreshListener(this);
return view;
}
@Override
public void onRefresh() {
// 更新処理を実装する
// ここでは単純に2秒後にインジケータ非表示
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 更新が終了したらインジケータ非表示
mSwipeRefreshLayout.setRefreshing(false);
}
}, 2000);
}
}
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment