How to implement a swiperefreshlayout with recyclerview and cardview

1

I have implemented a parserXML with Listview and cardview, but I do not know how to implement the swiperefreshlayout to refresh the content.

I do not know where to put the code to re-read the xml from my server, I've searched for tutorials but I can not find one to help me with this.

Thanks for your comments, in my class that loads the news I have it like that.

      public class fnoticias extends Fragment implements  adaptadorNoticia.OnItemClickListener{}

El codigo que ejecuta el parser con el adapter esta asi.

 public class TareaDescargaXml extends AsyncTask<String, Void, List<noticia>> {

        @Override
        protected void onPreExecute() {
            // show the progress bar
            spinner.setVisibility(View.VISIBLE);

        }
        @Override
        protected List<noticia> doInBackground(String... urls) {
            try {
                return parsearXmlDeUrl(urls[0]);
            } catch (IOException e) {
                return null; // null si hay error de red
            } catch (XmlPullParserException e) {
                return null; // null si hay error de parsing XML
            }
        }

        @Override
        protected void onPostExecute(List<noticia> result) {
            spinner.setVisibility(View.GONE );
            // Actualizar contenido del proveedor de datos
            noticia.Ultimas_Noticias = result;
            // Actualizar la vista del adaptador
            adaptador.notifyDataSetChanged();

        }
    }

and my layour I have it like that

    

<android.support.v7.widget.RecyclerView
    android:id="@+id/reciclador"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical" />

I hope you can guide me. Greetings.

    
asked by Alldesign Web 02.05.2016 в 17:21
source

1 answer

0

Just add as container of your ListView , the SwipeRefreshLayout

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swiperefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>

Here you can review the documentation:

link

    
answered by 02.05.2016 в 17:38