1

在我的应用程序中,我正在显示 facebook 墙流,我正在使用Facebook Graph API来获取每个帖子的数据。

有时当我快速滚动列表时,我会得到OutOfMemoryerror. 我真的不知道 facebook 应用程序使用什么技术来显示墙数据。

我可以知道他们使用的技术吗?

我以页面形式从 Facebook 获取数据。所以,我一次显示页面中的所有数据。正如我们在facebook 应用程序中看到的那样,我怎样才能只显示有限的数据?

class doInBack extends AsyncTask<URL, Integer, Long>
    {
        protected void onPreExecute() 
        { if(boolDialog){
            dialog=MyProgressDialog.show(Wall.this, null,null);
        }
        }
//      currentweb= webserv;
        @Override
        protected Long doInBackground(URL... arg0) {

            currentweb=webserv;

            Log.e("hi","doback parsing");

            try
            {   
            wallres=UrltoValue.getValuefromUrl(currentweb);
            Log.i("wallrespages",wallres);

                JSONObject jobj1=new JSONObject(wallres);

                JSONObject jobj2=jobj1.getJSONObject("paging");
                webserv= jobj2.getString( "next");

                 jsonArray = jobj1.getJSONArray("data");

                 for(int i=0;i<jsonArray.length();i++){

                    jsonObject = jsonArray.getJSONObject(i);





                    if(jsonObject.has("message")||jsonObject.has("picture")) {

                        try{


//                        msg[j]=jsonObject.getString("message");
                            if(jsonObject.has("message"))
                            {

                                msg.add(jsonObject.getString("message"));   
                            }
                            else{
                                msg.add("");    
                            }
                        }
                        catch(Exception e){
                            e.printStackTrace();
                        }

                        try{

//                            msg[j]=jsonObject.getString("message");
                                if(jsonObject.has("picture"))
                                {
                                    String firstpicture=jsonObject.getString("picture");
                                    String secondpicture=firstpicture.replaceAll("_s.jpg", "_n.jpg");
                                     Log.e("picurl",secondpicture);
                                     pic.add(secondpicture);

                                }
                                else{
                                    pic.add("");
                                }
                            }
                            catch(Exception e){
                                e.printStackTrace();
                            }                           objid.add(jsonObject.getString("id"));



                          JSONObject jobj=jsonObject.getJSONObject("from");
                           name.add(jobj.getString("name"));
                           id.add(jobj.getString("id"));

                           if(jsonObject.getString("type").equals("checkin")){
                               name.set(i,jobj.getString("name")+" "+"is at"+" "+jsonObject.getString("name"));
                            }

                           profimg.add("http://graph.facebook.com/"+id.get(j)+"/picture?type=square");

                           JSONObject commentjobj=jsonObject.getJSONObject("comments");
                            comment.add(commentjobj.getString("count"));

                            if(jsonObject.has("likes")) {

                                   Log.e("likeornot","likre");
                                JSONObject likesjobj=jsonObject.getJSONObject("likes");
                                likes.add(likesjobj.getString("count"));

                               String postid=jsonObject.getString("id");
//                                  graph_or_fql = "fql";
                                    String query = "SELECT likes.user_likes FROM stream WHERE post_id = \'" + postid + "'";

//                                                        Log.d("finalThreadID", finalThreadID);
                                    Bundle params = new Bundle();
                                    params.putString("method", "fql.query");
                                    params.putString("query", query);
//                                                        Utility.mAsyncRunner.request(null, params, new LikesListener());

                                String fqlResponse = Login.mFacebook.request(params);

                                   System.out.println(fqlResponse);

                                   JSONArray JOLikeresponse=new  JSONArray(fqlResponse);

                                  if(JOLikeresponse.length()!=0){
                                   JSONObject JOLikeObject = JOLikeresponse.getJSONObject(0);




                                if ( JOLikeObject.has("likes")) {
                                    String optlike,optlikesarray;
                                    JSONObject optLikes=JOLikeObject;
                                    JSONArray optLikesArray;
                                    try{

                                         optLikes = JOLikeObject.getJSONObject("likes");
                                         optlike="like";
                                    }
                                    catch(Exception e){

                                         optlike="unlike";
                                    }
//                                  
                                    if(optlike.equals("like")){

                                    if (optLikes.has("user_likes")) {
                                        String getUserLikes = optLikes.getString("user_likes");

                                        if (getUserLikes.equals("true")) {
                                            like_or_unlike.add("Unlike");
                                        } else if (getUserLikes.equals("false")) {
                                            like_or_unlike.add("Like");
                                        }
                                    }
                                    else {

                                           like_or_unlike.add("Like");
                                    }
                                } else {

                                       like_or_unlike.add("Like");
                                }

                                }
                                //if likes object is not there in like response
                                else {

                                       like_or_unlike.add("Like");
                                }
                                  }

                               //if the like response Array length is zero   
                                else {

                                       like_or_unlike.add("Like");
                                }//FQL query object

                            }

                    //If likes are not there        
                               else{
                                   likes.add("0");
                                   like_or_unlike.add("Like");
                               }


                            weburl.add(currentweb);

                           Log.e("comment", comment.get(j));
//                         bitmap[j]= getBitmapFromURL(profimg[j]);
//                         profimg1.setImageBitmap(bitmap[j]);
//                         imageLoader.DisplayImage( profimg[j].replace(" ", "%20"), profimg1) ;
//                         System.out.println( bitmap[j]);
//                         j++;
//                          f=j;


                           String getCreatedTime = jsonObject.getString("created_time");
//                         long finalTimeStamp = Long.valueOf(getCreatedTime);
//                         SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
//                         String timestamp = dateFormatter.format(new Date(finalTimeStamp * 1000L));

                           SimpleDateFormat formatter = getDateFormat();
                           ParsePosition pos = new ParsePosition(0);
                           long then = formatter.parse(getCreatedTime, pos).getTime();
                           long now = new Date().getTime();

                           long seconds = (now - then)/1000;
                           long minutes = seconds/60;
                           long hours = minutes/60;
                           long days = hours/24;

                           String friendly = null;
                           long num = 0;
                           if (days > 0) {
                               num = days;
                               friendly = days + " day";
                           } else if (hours > 0) {
                               num = hours;
                               friendly = hours + " hour";
                           } else if (minutes > 0) {
                               num = minutes;
                               friendly = minutes + " minute";
                           } else if(seconds>0) {
                               num = seconds;
                               friendly = seconds + " second";
                           }
                           else{
                               friendly = "few seconds";
                           }
                           if (num > 1) {
                               friendly += "s";
                           }
                           String postTimeStamp = friendly.toLowerCase() + " ago";
                           Log.e("date",postTimeStamp );
                           date.add(postTimeStamp);

                           j++;
                    }
                    }

//                if(jsonObject.getString("message")!=""){
//                    msg[i]=jsonObject.getString("message");
//                     
//                    JSONObject jobj=jsonObject.getJSONObject("from");
//                     name[i]= jobj.getString("name");
//                     id[i]=jobj.getString("id");
//                     Log.e("msg",msg[i]);
//                     Log.e("name",name[i]);
//                     Log.e("id",id[i]);
//                     }
//                       
//                   }





            }

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


            return null;
        }

        protected void onPostExecute(Long result) { 

            try
            {   if(addFooter){
                 listView.addFooterView(footerView);
            }

                addFooter=false;
                System.out.println(scroll);
                if(scroll){

                 adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,comment,objid,weburl,likes, like_or_unlike,date);
                listView.setAdapter(adapter);
                  listView.postDelayed(new Runnable() {

//                      @Override
                        public void run() {

                            listView.onRefreshComplete();
                        }
                    }, 2000);
                if(boolDialog){
                dialog.dismiss();
                }
                }

         else{
//           adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,bitmap,comment,objid,weburl);
             adapter.notifyDataSetChanged();
              listView.postDelayed(new Runnable() {

//                  @Override
                    public void run() {

                        listView.onRefreshComplete();
                    }
                }, 2000);
            }
                if(boolDialog){
                dialog.dismiss();
                }
            }



            catch(Exception e)
            {
                e.printStackTrace();
                if(boolDialog){
                    dialog.dismiss();
                    }
            }
            boolDialog=false;       
    }

    }

    private static SimpleDateFormat getDateFormat() {
        return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
    }
4

0 回答 0