5

qui sto usando il cassetto scorrevole. in quello su clic home icon mostra 3 schede
1) quale concetto dovrei applicare per la scheda?
2) Voglio applicare pulltoreferesh e loadmore in listview come Facebook? in quanto hai anche visto che quando si scorre la barra di avanzamento si nasconde e la richiesta si cancella.

enter image description herepull per aggiornare e loadmore listview come facebook

risposta

4
public class ListDemo extends Fragment{ 
    ArrayAdapter<String> files; 
    private LinkedList<String> mListItems; 
    PullAndLoadListView lyt ; 
    // ListView lv1; 

    // The data to be displayed in the ListView 
    private String[] mNames = { "Fabian", "Carlos", "Alex", "Andrea", "Karla", 
      "Freddy", "Lazaro", "Hector", "Carolina", "Edwin", "Jhon", 
      "Edelmira", "Andres" }; 

    // The data to be displayed in the ListView 
    private String[] mAnimals = { "Perro", "Gato", "Oveja", "Elefante", "Pez", 
      "Nicuro", "Bocachico", "Chucha", "Curie", "Raton", "Aguila", 
      "Leon", "Jirafa" }; 



    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     super.onCreateView(inflater, container, savedInstanceState); 
     final View v = inflater.inflate(R.layout.tab_frag3_layout, container, false); 
     mListItems = new LinkedList<String>(); 
     mListItems.addAll(Arrays.asList(mNames)); 
     lyt = (PullAndLoadListView)v.findViewById(R.id.tab_frag3_listview1); 

     if (container == null) { 
      return null; 
     } 

     files = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,mListItems); 
     lyt.setAdapter(files); 
     lyt.setOnRefreshListener(new OnRefreshListener() { 

      @Override 
      public void onRefresh() { 
       // TODO Auto-generated method stub 
       new PullToRefreshDataTask().execute(); 
      } 
     }); 
     lyt.setOnLoadMoreListener(new OnLoadMoreListener() { 

      @Override 
      public void onLoadMore() { 
       // TODO Auto-generated method stub 
       new LoadMoreDataTask().execute(); 
      } 
     }); 
     return v; 

    } 
    private class LoadMoreDataTask extends AsyncTask<Void, Void, Void> { 

     @Override 
     protected Void doInBackground(Void... params) { 

      if (isCancelled()) { 
       return null; 
      } 

      // Simulates a background task 
      try { 
       Thread.sleep(1000); 
      } catch (InterruptedException e) { 
      } 

      for (int i = 0; i < mAnimals.length; i++) 
       mListItems.add(mAnimals[i]); 

      return null; 
     } 

     @Override 
     protected void onPostExecute(Void result) { 
      mListItems.add("Added after load more"); 

      // We need notify the adapter that the data have been changed 
      files.notifyDataSetChanged(); 

      // Call onLoadMoreComplete when the LoadMore task, has finished 
      lyt.onLoadMoreComplete(); 

      super.onPostExecute(result); 
     } 

     @Override 
     protected void onCancelled() { 
      // Notify the loading more operation has finished 
      lyt.onLoadMoreComplete(); 
     } 
    } 

    private class PullToRefreshDataTask extends AsyncTask<Void, Void, Void> { 

     @Override 
     protected Void doInBackground(Void... params) { 

      if (isCancelled()) { 
       return null; 
      } 

      // Simulates a background task 
      try { 
       Thread.sleep(1000); 
      } catch (InterruptedException e) { 
      } 

      for (int i = 0; i < mAnimals.length; i++) 
       mListItems.addFirst(mAnimals[i]); 

      return null; 
     } 

     @Override 
     protected void onPostExecute(Void result) { 
      mListItems.addFirst("Added after pull to refresh"); 

      // We need notify the adapter that the data have been changed 
      files.notifyDataSetChanged(); 

      // Call onLoadMoreComplete when the LoadMore task, has finished 
      lyt.onRefreshComplete(); 

      super.onPostExecute(result); 
     } 

     @Override 
     protected void onCancelled() { 
      // Notify the loading more operation has finished 
      lyt.onLoadMoreComplete(); 
     } 
    } 

} 

qui è Sourc Codice della libreria pull-to-refresh and load-more.

+0

puoi caricare anche il tuo file xml? –

+0

per favore aggiungi listview personalizzato nel tuo xml come questo https://github.com/shontauro/android-pulltorefresh-and-loadmore#layout-for-pullandload-listview –

+1

ok grazie .. l'ho fatto :) –

1

Non ho usato questa libreria me stesso ed è stato interrotto (2 mesi fa), ma sembra grande con esempi e tutti:

https://github.com/chrisbanes/Android-PullToRefresh/wiki/Quick-Start-Guide

Da quello che ho letto, in sostanza è necessario sostituire il proprio ListView con ListView della biblioteca e importare il file jar e siete pronti ad andare ;-)

+0

sto usando 2 biblioteche android-supporto-v4.jar, LoadMoreListView (com.costum.android.widget) –

+0

Così qual è il problema esattamente? Ho un link a una libreria per pull-refresh in listview o listfragment. Non ho mai sentito parlare dell'altra biblioteca e non ho intenzione di guardarlo adesso. Perché non provare il mio link, invece? – Darwind

Problemi correlati