I have a refresh button on one of my activities. Whenever a user presses that button I want to use the SwipeRefreshLayout refreshing animation, but I do not want the user to be able to swipe down to refresh the screen . Is there any way I can do this?
Have you tried;
//button clicked...
//show loader, disable further pulltorefresh requests
//do some timed task
pullToRefresh.setRefreshing(true);
//Task done...
//hide loader, allow pulltorefresh requests
pullToRefresh.setRefreshing(false);
I use in a fragment;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.my_fragment, container, false);
pullToRefresh = (SwipeRefreshLayout)view.findViewById(R.id.pullToRefresh);
pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshContent();
}
});
Button refresh = (Button) view.findViewById(R.id.refreshMethod);
refresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
refreshContent();
}
});
return view;
}
refreshContent() {
//call Async task via RetrieveFeedTask extends AsyncTask<Void, Void, String> {}
new RetrieveFeedTask().execute();
}
class RetrieveFeedTask extends AsyncTask<Void, Void, String> {
private Exception exception;
protected void onPreExecute() {
recycler.clearOnScrollListeners();
pullToRefresh.setRefreshing(true);
}
protected String doInBackground(Void... urls) {
//do task like get JSON from server
//try sleep for a bit
try {
Thread.sleep(2000);
} catch (InterruptedException error) {
}
}
protected void onPostExecute(String response) {
//do post stuff
//hide pullfresh, full refresh view done
pullToRefresh.setRefreshing(false);
}
}
have you tried swipeRefreshLayout.setEnabled(false);
? And then you could simply call the setRefreshing(true)
and setRefreshing(false)
in your button's listener
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.