简体   繁体   English

从inputsream到列表视图将10个项目下载到下一个10个项目中

[英]download 10 items to the next 10 items to the next from an inputsream to a listview - android

In my android application, I am downloading content through an input stream. 在我的android应用程序中,我正在通过输入流下载内容。 At the moment from my code all the content is loaded at once from the server and parser via an asynctask then to a listview. 目前,从我的代码开始,所有内容都通过asynctask从服务器和解析器一次加载到列表视图中。 How can I download items from the server through an input in batches of ten from the below snippets 如何通过以下片段中的十个批次的输入从服务器下载项目

private String downloadData()
    {
        HttpURLConnection con=Connector.connect(urlAddress);
        if(con==null)
        {
            return null;
        }

        try
        {
            InputStream is=new BufferedInputStream(con.getInputStream());
            BufferedReader br=new BufferedReader(new InputStreamReader(is));

            String line;
            StringBuffer jsonData=new StringBuffer();


            return jsonData.toString();

        } catch (IOException e) {
            e.printStackTrace();
        }


        return null;
    }

Please how can I use the dowloaddata() I created to pull items from the server in batches of 10 then accordingly to the listview while on scroll 请在滚动时,如何使用创建的dowloaddata()从服务器中按10个批次拉出项目,然后相应地将其拉到listview

You need set scroll Listener for your list View Using: 您需要为列表设置滚动监听器。

listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

                int lastInScreen = firstVisibleItem + visibleItemCount;
                if(!loadingMore && (lastInScreen == totalItemCount)) {
                    new Thread(() -> {
                        loadingMore = true; // loadingMore is local boolean to check if you already loaded
                        runOnUiThread(() -> {
                            //Here You Can Execute your AsyncTask and update your List of Items
                            adapter.notifyDataSetChanged(); // notify the data in list of items has changed
                            loadingMore = false;
                        });

                    }).start();
                }

            }
        });

You can read this tutorial for creating ENDLESS LIST VIEW https://www.mindstick.com/Articles/1570/endless-list-view-adapter-in-android 您可以阅读本教程以创建ENDLESS LIST VIEW https://www.mindstick.com/Articles/1570/endless-list-view-adapter-in-android

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

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