use android dynamicaly load more items to the listview need help

后端 未结 2 1895
深忆病人
深忆病人 2021-02-06 19:33
package fshizzle.com;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;

imp         


        
2条回答
  •  情歌与酒
    2021-02-06 20:01

    For more infos here my code use for dynamicaly load listview ;)

    this.getListView().setOnScrollListener(new OnScrollListener(){
    
            //useless here, skip!
            public void onScrollStateChanged(AbsListView view, int scrollState) {}
    
            //dumdumdum         
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
    
    
                //what is the bottom iten that is visible
                int lastInScreen = firstVisibleItem + visibleItemCount;             
    
                //is the bottom item visible & not loading more already ? Load more !
                if((lastInScreen == totalItemCount) && (loadingMore)){
                Adapter.notifyDataSetChanged(); 
                }
                if((lastInScreen == totalItemCount) && !(loadingMore)){
                    i++;
                    //on envoie la page a aller chercher
                    String page3 = getPage(var_global.URL+"listview.php?login="+login+"&page="+i);
                    Log.i(LOG_TAG, page3);
    
                    JSONObject json = JSONfunctions.getJSONfromURL(var_global.URL+"json/listview/"+login+".json");
    
                    try{
    
                        JSONArray  earthquakes = json.getJSONArray("infos");
    
                        for(int i=0;i map = new HashMap();    
                            JSONObject e = earthquakes.getJSONObject(i);
    
                            //si user == a endlist
                            if (e.getString("user").equals("endlistfshizzle")) {
                                loadingMore = true;
                            }
                            map.put("id",  String.valueOf(i));
                            map.put("name", "infos name:" + e.getString("user"));
                            map.put("age", "age: " +  e.getString("age"));
    
                            URL pictureURL = new URL(var_global.URL+"upload/thumbs/"+e.getString("image"));
                            Bitmap bitmap = BitmapFactory.decodeStream(pictureURL.openStream());
                            map.put("img",bitmap);              
                            //http://www.imagemagick.org/Usage/thumbnails/                  
                            mylist.add(map);            
                        }       
                    }catch(JSONException e)        {
                         Log.e("log_tag", "Error parsing data "+e.toString());
                    } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }                           
    
                    Adapter.notifyDataSetChanged();
                }
            }
        });                
    

    Good programming at all !!

提交回复
热议问题