tutaj używam przesuwanej szuflady. w tym na kliknij ikona domu pokazuje 3 zakładki
1) Której koncepcji należy zastosować do zakładki?
2) Chcę zastosować pulltoreferesh
i loadmore
w widoku listy jak Facebook? w tym, że widziałem także, że po przewinięciu do góry pasek postępu zostaje ukryty, a żądanie anulowania. Wyciągnij, aby odświeżyć i wczytać więcej listview jak Facebook
Odpowiedz
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();
}
}
}
tutaj jest Sourc Kod e biblioteki pull-to-refresh and load-more.
Nie używałem tej biblioteki siebie i zostało przerwane (2 miesiące temu), ale wygląda świetnie z przykładami i wszystkich:
https://github.com/chrisbanes/Android-PullToRefresh/wiki/Quick-Start-Guide
Z tego co czytałem, zasadniczo trzeba wymienić swoją ListView ListView z biblioteki i zaimportować plik jar i jesteś dobry, aby przejść ;-)
używam 2 bibliotek android-support-v4.jar, LoadMoreListView (com.costum.android.widget) –
Tak jaki jest dokładnie problem? Mam link do biblioteki do odświeżania w widoku listview lub listfragment. Nigdy nie słyszałem o drugiej bibliotece i nie zamierzam teraz jej oglądać. Może zamiast tego wypróbujesz mój link? – Darwind
Użyj tej biblioteki, Użyłem dni temu i działa idealnie:
Czy możesz również przesłać plik ur xml? –
proszę dodać niestandardowy listview w swoim xml w ten sposób https://github.com/shontauro/android-pulltorefresh-and-loadmore#layout-for-pullandload-listview –
ok, dziękuję .. zrobiłem to :) –