SwipeRefreshLayout, refresh in background thread

SwipeRefreshLayout, refresh in background thread - Hello Friend GENERAL INFO FOR ANDROID DEVELOPMENT, In the article you read this time with the title SwipeRefreshLayout, refresh in background thread, We have prepared this article for you to read and retrieve information there in. Hopefully the contents of postings Artikel Android code sample: Detecting Gestures, Artikel Android code sample: SwipeRefreshLayout, Artikel Android code sample: thread, We write this you can understand. Alright, good read.

The Title : SwipeRefreshLayout, refresh in background thread
link : SwipeRefreshLayout, refresh in background thread

Read also

SwipeRefreshLayout, refresh in background thread

Last post show a basic example of SwipeRefreshLayout. But, normally refreshing involve some longtime task; such as loading data from Internet. This example show how to refresh with longtime task in background thread.

package com.blogspot.android_er.androidswiperefresh;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {

SwipeRefreshLayout swipeRefreshLayout;
ListView swipeList;

List<String> myList;
ListAdapter adapter;

protected void onCreate(Bundle savedInstanceState) {

swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swiperefreshlayout);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
public void onRefresh() {

swipeList = (ListView)findViewById(R.id.swipelist);

myList = new ArrayList<>();
adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1, myList);

swipeList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = (String) parent.getItemAtPosition(position);
Toast.makeText(MainActivity.this, item, Toast.LENGTH_LONG).show();

private void refresh(){

final int pos = myList.size();
myList.add(pos, "Refreshing...");

//refresh long-time task in background thread
new Thread(new Runnable() {
public void run() {
try {
//dummy delay for 2 second
} catch (InterruptedException e) {

//update ui on UI thread
runOnUiThread(new Runnable() {
public void run() {
String currentDateTime =
DateFormat.getDateTimeInstance().format(new Date());
myList.set(pos, pos + " - " + currentDateTime);


Keep using the layout in last post.

SwipeRefreshLayout, work with RecyclerView

Thus Article SwipeRefreshLayout, refresh in background thread

The End Article SwipeRefreshLayout, refresh in background thread This time, hopefully can give benefits to all of you. well, see you in posting other articles.

You are now reading the article SwipeRefreshLayout, refresh in background thread with the link address http://xorislogo.blogspot.com/2016/05/swiperefreshlayout-refresh-in.html

0 Response to "SwipeRefreshLayout, refresh in background thread"

Post a Comment