2
How do I update the APP activity after the user swipes their finger down on the screen. How to detect this action to trigger an event in my code?
2
How do I update the APP activity after the user swipes their finger down on the screen. How to detect this action to trigger an event in my code?
5
To use the SwipeRefreshLayout
is quite simple.
If you have not yet used 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 the Gradle, then it is necessary to import the Support Library v4 following this tutorial: support-library/setup.
SwipeRefreshLayout
as 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
, configure the 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 interface SwipeRefreshLayout.OnRefreshListener
.
@Override
public void onRefresh() {
// Executar a atualizacao
}
mSwipeToRefresh.setRefreshing(false);
Hello Wakim! Thanks for the example, but I’m still not able to build an example. Could you send me a project ready for Eclipse?
@Vitormendanha, unfortunately I no longer use the Eclipse in a long time, I can try later to build a functional example. But it would be faster maybe you keep adding the question the mistakes you are having, to get to the solution.
I will test with Android Studio. Thank you.
Browser other questions tagged android android-layout
You are not signed in. Login or sign up in order to post.
You could use the
SwipeRefreshLayout
which is present in support-library-v4.– Wakim
Hello Wakim! I would appreciate it if you put up an example of use.
– Vitor Mendanha