How do I update APP activity after the user swipes the screen down. How do I detect this action so I can trigger an event in my code?
How do I update APP activity after the user swipes the screen down. How do I detect this action so I can trigger an event in my code?
To use SwipeRefreshLayout
is quite simple.
If you do not already use the Support Library v4 , then add the same to your project:
dependencies {
// Demais dependencias do seu projeto
compile 'com.android.support:support-v4:22.1.1'
}
If you do not use Gradle then you need to import the Support Library v4 by following this tutorial: support-library / setup .
SwipeRefreshLayout
as the root of your layout. An example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_refresh_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Restante das views do seu layout -->
</android.support.v4.widget.SwipeRefreshLayout>
Activity
or Fragment
, set SwipeRefreshLayout
: // Recupera o SwipeRefreshLayout
mSwipeToRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_container);
// Seta o Listener para atualizar o conteudo quando o gesto for feito
mSwipeToRefresh.setOnRefreshListener(this);
// O esquema de cores
mSwipeToRefresh.setColorSchemeResources(
R.color.indigo_300,
R.color.indigo_400,
R.color.indigo_500,
R.color.indigo_600,
R.color.indigo_700,
R.color.indigo_800,
R.color.indigo_900
);
SwipeRefreshLayout
notify: Your Activity should implement the SwipeRefreshLayout.OnRefreshListener
interface.
@Override
public void onRefresh() {
// Executar a atualizacao
}
mSwipeToRefresh.setRefreshing(false);