這裏我使用滑動抽屜。在這點擊主頁圖標它顯示3個標籤
1)我應該爲哪個標籤應用標籤?
2)我想申請pulltoreferesh
和loadmore
像facebook一樣的listview? 因爲你也看到了當向上滾動進度條時隱藏和請求取消。
拉到刷新和加載更多像facebook的列表視圖
回答
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();
}
}
}
這裏是源碼e代碼pull-to-refresh and load-more庫。
我還沒有使用這個庫自己和它已經停產(2個月前),但它與實例和所有看起來不錯:
https://github.com/chrisbanes/Android-PullToRefresh/wiki/Quick-Start-Guide
從我讀,基本上你需要使用圖書館的列表視圖來代替自己的ListView和導入jar文件,你是好去;-)
我使用2個庫Android的支持,v4.jar,LoadMoreListView(com.costum.android.widget) – 2013-03-13 11:58:29
所以究竟是什麼問題?我有一個鏈接到一個庫,用於在listview或listfragment中進行拉式刷新。我從來沒有聽說過其他圖書館,也不打算現在看它。爲什麼不嘗試我的鏈接呢? – Darwind 2013-03-13 16:20:43
使用這個庫,我幾天前使用和工作完美:
- 1. C# - 將圖像加載到圖像列表和列表視圖
- 2. 更新/刷新列表視圖
- 3. 列表視圖刷新android
- 4. Android列表視圖刷新
- 5. 刷新列表視圖
- 6. Android列表視圖刷新
- 7. 刷新Android列表視圖
- 8. REST和列表視圖刷新
- 9. 畢加索圖像重新加載滾動在列表視圖
- 10. 在列表視圖中加載圖像
- 11. 在列表視圖中加載圖像
- 12. EGO表視圖拉刷新太敏感
- 13. 拉到刷新UWP - 網格視圖?
- 14. 實現Chris Banes的拉動與列表視圖一起刷新
- 15. 列表刷新/重新加載模板
- 16. 圖像不刷新jQuery加載
- 17. 刷新ASP.NET MVC圖像加載
- 18. 錯誤的圖像加載時在列表視圖中加載圖像
- 19. ListView加載更多和url圖像
- 20. Codenameone刷新圖像的列表,而無需重新加載頁面
- 21. 重新加載數據不會刷新表格視圖
- 22. 動態改變列表視圖大小和加載圖像
- 23. 從服務器和列表視圖中加載圖像
- 24. 如何刷新列表視圖當列表視圖
- 25. 如何更實現了加載表視圖時滾動到底?(即拉起刷新)
- 26. ClassCastException當嘗試加載更多的列表視圖
- 27. 自動刷新和下載Asirra圖像
- 28. 將很多圖像加載到鈦圖像視圖
- 29. Spring:列表在刷新時重新加載了很多次
- 30. 使用通用圖像加載器在列表視圖中加載圖像
你能否請上傳你的xml文件呢? – 2014-08-20 07:16:02
請在您的xml中添加自定義列表視圖像這樣https://github.com/shontauro/android-pulltorefresh-and-loadmore#layout-for-pullandload-listview – 2014-08-20 08:42:06
好的謝謝..我做到了:) – 2014-08-20 10:45:48