Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android加载更多列表视图_Android_Facebook_Listview_Autoload - Fatal编程技术网

Android加载更多列表视图

Android加载更多列表视图,android,facebook,listview,autoload,Android,Facebook,Listview,Autoload,您好,我的android应用程序中有一个listview。当我的应用程序打开时,我会加载它,如果用户滚动到列表的末尾,列表视图会自动加载。但在第二个卷轴中,它不会自动加载。这是我的密码: lstinteract.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) {

您好,我的android应用程序中有一个listview。当我的应用程序打开时,我会加载它,如果用户滚动到列表的末尾,列表视图会自动加载。但在第二个卷轴中,它不会自动加载。这是我的密码:

lstinteract.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            // TODO Auto-generated method stub
            int lastInScreen = firstVisibleItem + visibleItemCount;    
               if((lastInScreen == totalItemCount) && !(loadingMore2)){   
                   loadingMore2=true;

                   GetFacebookInitDatas fb = new GetFacebookInitDatas();
                   fb.execute();

                    loadingMore2=false;


               }
        }
    });



    private class GetFacebookInitDatas extends AsyncTask<String, Void, Void>
{

    @Override
    protected Void doInBackground(String... params) {
        // TODO Auto-generated method stub

        final ArrayList<String> interactsenders = new ArrayList<String>();
        final ArrayList<String> interactposts = new ArrayList<String>();
        final ArrayList<String> interactimages = new ArrayList<String>();
        final ArrayList<String> interactlinks = new ArrayList<String>();

        try {
            inprevpage = intlinks.getString("previous");
            innextpage = intlinks.getString("next");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {

            System.out.println(innextpage);
            URL url = new URL(innextpage);
            URLConnection connection = url.openConnection();
            HttpURLConnection httpConnection = (HttpURLConnection) connection;
            int responseCode = httpConnection.getResponseCode();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                InputStream in = httpConnection.getInputStream();

                BufferedReader rd = new BufferedReader(new InputStreamReader(
                        in, Charset.forName("UTF-8")));
                String jsonText = readAll(rd);
                JSONObject data = new JSONObject(jsonText);

                if (data != null) {
                    JSONArray duyurular = null;
                    try {
                        duyurular = data.getJSONArray("data");
                        intlinks = data.getJSONObject("paging");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    String hocaid = null;
                    String postid=null;
                    String sender = null;
                    String mesaj = null;
                    for (int i = 0; i < duyurular.length(); i++) {
                        JSONObject obj = null;
                        try {
                            obj = duyurular.getJSONObject(i);
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        try {
                            postid = obj.getString("id");
                            postids.add(postid);
                            mesaj = obj.getString("message");
                        } catch (JSONException e) {
                            mesaj = "This attachment may have been removed or the person who shared it may not have permission to share it with you.";
                        }
                        JSONObject fromObj = null;
                        try {
                            fromObj = obj.getJSONObject("from");
                        } catch (JSONException e1) {
                            System.out.println("Hata 2");
                            e1.printStackTrace();
                        }
                        try {
                            sender = fromObj.getString("name");
                            hocaid = fromObj.getString("id");
                        } catch (JSONException e) {
                            sender = "Name didn't recieved.";
                        }
                        if (lecturerID.equals(hocaid)) {

                        } else {
                                    interactsenders.add(sender);
                                    interactposts.add(mesaj);
                                    interactimages.add("http://graph.facebook.com/"+ hocaid + "/picture");
                                    interactlinks.add("http://www.facebook.com/544570888900558/posts/"+ postid);

                        }
                    }


                    System.out.println("Size: "+postids.size());


                    ListToList(interactsenders, profname);
                    ListToList(interactposts, intercontent);
                    ListToList(interactimages, profpic);
                    ListToList(interactlinks, facebookunlink);

                    }
                }


        } catch (Exception e) {
            System.out.println(e.toString());
        }
        return null;
    }

    protected void ListToList(ArrayList<String> source,ArrayList<String> destination) {
        for (int i = 0; i < source.size(); i++) {
            destination.add(source.get(i));
        }
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        interaction=new AnnounceAdapter(main, profname,profpic,intercontent);
        interaction.notifyDataSetChanged();
    }
}
试一试推杆

loadingMore2=false;
进入AsyncTask的postExecute方法,而不是onScroll。按照现在的方式,AsyncTask可以一次运行多次,因为在上一次下载完成之前,
loadingMore2
会切换为true。这可能就是问题所在

loadingMore2=false;