简体   繁体   English

在“拉动”中禁用加载以刷新列表视图

[英]Disable loading in Pull to refresh listview

I am having Pull to Refresh https://github.com/chrisbanes/Android-PullToRefresh as given in this link. 我在此链接中给出了Pull to Refresh https://github.com/chrisbanes/Android-PullToRefresh Everything works fine. 一切正常。 But when my list item finishes, the loading icon and pull to refresh label is still visible. 但是,当我的列表项完成后,加载图标和“刷新”标签仍然可见。 So, how to disable the scrolling when end of list reached? 那么,如何在到达列表末尾时禁用滚动?

mainListView.setOnRefreshListener(new OnRefreshListener() {

                @Override
                public void onRefresh(PullToRefreshBase refreshView) {

                                        String total_bk_count = subCategory                                                 .getTotal_Book_Count();
                                        count_of_book = Integer.parseInt(total_bk_count);
                                        listCountt = mainbooksAdpater.getCount();
                                        Log.e("StroreActivity","Total book count---====----====---+"+count_of_book);
                                        Log.e("StroreActivity","list Count---====----====---+"+listCountt);
                                        if(listCountt < count_of_book)
                                        {

                                            int bookCount = Common.getBookCountNumber();
                                            Common.setBookCount(bookCount+1);
                                            String refresh_Pull_Url = Common.getUrlForeCategoryBooks(id, Common.NUMBER_OF_BOOKS_PER_REQUEST);
                                            Log.e("Rathis to Check url", Common.getUrlForeCategoryBooks(id, Common.NUMBER_OF_BOOKS_PER_REQUEST));
                                            PulltoRefreshAsync onCatBooksTaskScroll = new PulltoRefreshAsync(Common.getUrlForeCategoryBooks(id, Common.NUMBER_OF_BOOKS_PER_REQUEST));
                                            onCatBooksTaskScroll.execute();

                                        Log.e("StroreActivity","Total Book count::" + book_count_no);

                                    }
                                        else
                                        {

                                        mainListView.setMode(Mode.DISABLED);    
                                        Toast.makeText(getApplicationContext(), "end of list", Toast.LENGTH_SHORT).show();

                                        }
                                    }
                                });

Asynctask Class: Asynctask类别:

public class PulltoRefreshAsync extends AsyncTask<Object,Object,Object> {
    int refreshCount;
    String refresh_URL;
    public PulltoRefreshAsync(String url) {
        refresh_URL = url;

    }

    /*
     * PulltoRefreshAsync(int i) { refreshCount = i; }
     */

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Log.e("Checking Purpose", refresh_URL);




    }

    @Override
    protected String doInBackground(Object... arg0) {
        JsonParserRefresh jp = new JsonParserRefresh();
        Log.e("StroreActivity","Array to String::" + refresh_URL);
        String jsonString = jp.getJSONFromURL(refresh_URL);
        Log.e("StroreActivity","JsonString::" + jsonString);
        jsonParseForCategoryBooksGridScroll(jsonString);
        return null;
    }

    @Override
    protected void onPostExecute(Object result) {
        super.onPostExecute(result);
        /*
         * if(mProgressDialog.isShowing()) { mProgressDialog.dismiss(); }
         */

        final MainBooksAdapter mainbooksAdpater = new MainBooksAdapter(
                StoreActivity.this, R.layout.aa, mainBooksList);
        final int old_pos = mainListView.getRefreshableView()
                .getFirstVisiblePosition() + 1;
        mainListView.setAdapter(mainbooksAdpater);

        tvvisiblebookCount.setText("" + mainbooksAdpater.getCount());

        /*if(listCountt < count_of_book)
        {

            mainListView.setMode(Mode.DISABLED);*/
        mainListView.post(new Runnable() {

            @Override
            public void run() {
                mainListView.onRefreshComplete();
                mainListView.getRefreshableView().setSelection(old_pos);
            }
        });
        //}
        mainbooksAdpater.notifyDataSetChanged();

    }



}

For other people who might have similat issue: 对于可能有类似问题的其他人:

you don't have to implement it this way 您不必以这种方式实施

mainListView.post(new Runnable() {

            @Override
            public void run() {
                mainListView.onRefreshComplete();
                mainListView.getRefreshableView().setSelection(old_pos);
            }
        });

instead do just like this : 而是这样做:

mainListView.onRefreshComplete();

one more thing I noticed, instead of saving the old pos value to get back to it, why not just use notifyDataSetChanged it leaves the position of the list the way it is, just try not to re-instanciate you list, ie: mainBooksList = ..., instead try this: 我注意到了另一件事,而不是保存旧的pos值以返回它,为什么不只使用notifyDataSetChanged而是按notifyDataSetChanged列表的位置,而是尽量不要重新实例化列表,即:mainBooksList = ...,请尝试以下操作:

mainBooksList.clear();
mainBooksList.addAll(YOUR DATA);
adapter.notifyDataSetChanged();

voila! 瞧!

hope this helps someone 希望这可以帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM