when I using SwipeRefreshLayout it will refresh when I try to scroll up at the top of the list. this time I want to apply the same thing but the trigger to refresh is when at the bottom of the list but still want to scroll down. Does anyone know how can I achieve that? really appreciate your help. Thank you in advance. however in java, please.
Step 1: code to res/layout/activity_main.xml
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:id = "@+id/swipeRefresh"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = ".MainActivity">
<LinearLayout
android:layout_width = "wrap_content"
android:gravity = "center"
android:layout_height = "wrap_content">
<TextView
android:id = "@+id/text"
android:textSize = "30sp"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "Hello World!"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
In the above code we have given swipeRefreshLayout as parent layout, when user swipe layout, it can refresh child view.
step3: code to src/MainActivity.java
package com.example.aji.myapplication;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
SwipeRefreshLayout swipeRefresh;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView textView = findViewById(R.id.text);
swipeRefresh = findViewById(R.id.swipeRefresh);
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//your stuff
swipeRefresh.setRefreshing(false);
}
});
}
}
lets change hello wolrd to shafri
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
i++;
textView.setText("shafri"+i);
swipeRefresh.setRefreshing(false);
}
});
HappyCode!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.