【问题标题】:pull to refresh and loadmore listview like facebook [closed]拉动以刷新和加载更多列表视图,如 facebook [关闭]
【发布时间】:2013-03-12 13:34:46
【问题描述】:

我在这里使用滑动抽屉。在点击 主页图标 时,它会显示 3 个标签
1) 我应该为标签申请哪个概念?
2) 我想在 facebook 之类的列表视图中申请 pulltorefereshloadmore 吗? 因为您还看到,当向上滚动时,进度条会隐藏并请求取消。

【问题讨论】:

    标签: android android-fragments android-viewpager android-fragmentactivity viewpagerindicator


    【解决方案1】:
    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();
            }
        }
    
    }
    

    这里是pull-to-refresh and load-more 库的源代码。

    【讨论】:

    • 你能上传你的xml文件吗?
    • 请像这样在你的xml中添加自定义列表视图github.com/shontauro/…
    • 好的,谢谢 .. 我做到了 :)
    【解决方案2】:

    使用这个库,我几天前就使用过并且工作完美:

    RefreshableListView

    【讨论】:

      【解决方案3】:

      我自己没有使用过这个库,它已经停止使用(2 个月前),但它看起来很棒,有示例和所有内容:

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

      根据我的阅读,基本上你需要用库的列表视图替换你自己的列表视图并导入 jar 文件,你很高兴;-)

      【讨论】:

      • 我正在使用 2 个库 android-support-v4.jar,LoadMoreListView(com.costum.android.widget)
      • 那么到底是什么问题呢?我有一个指向库的链接,用于在列表视图或列表片段中进行拉刷新。我从未听说过其他图书馆,也不打算现在看。为什么不试试我的链接呢?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 2012-02-17
      • 2013-11-22
      • 2013-03-23
      • 2013-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多