简体   繁体   中英

How to show huge data (50,000 records) in listview in android

we have a server i am getting response in JSON format and i have a customized listview where each row showing 4-5 texts now i want my application to show list as it is loading data from response and reflect in listview i have used async task for it code is below but it is reflecting data after getting all the data i want it to display as soon as it is responding :

class UpdateLoadingAirport extends AsyncTask<String, Integer, String> 
{

    @Override
    protected String doInBackground(String... params) {
        String page=params[0];
           System.out.println("Pageno====================>asynctask for loading first is :"+page);
            String url="http://xyz/"+page;  


        //  String urlToSend="http://182.72.123.138:9502/AirportWebService.asmx/Get50Airports?page=";
            try {


                HttpGet post=new HttpGet(url);
                HttpClient client=new DefaultHttpClient();
                org.apache.http.HttpResponse response=client.execute(post);

                StatusLine statusLine = response.getStatusLine();
                int statusCode = statusLine.getStatusCode();
                if (statusCode == 200)
                {
                    HttpEntity entity = response.getEntity();
                    InputStream content = entity.getContent();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(content));

                    System.out.println("<-----------------------Registration Success------------------------>");

                    String line;
                    StringBuilder  stringBuilder= new StringBuilder();
                    while ((line = reader.readLine())!=null) {
                        stringBuilder.append(line);
                    }
                    reader.close();
                    content.close();
                    resultOf= stringBuilder.toString();
                    //saveAirportFBO(resultOf);

                    //System.out.println("Result of url :"+resultOf);
                    //parsedString=getJSONStringFormat(resultOf);

                     JSONObject updatedAirportJSONObject;
                    try {
                        updatedAirportJSONObject = new JSONObject(resultOf);
                        JSONArray updatedAirportJSONArray1;

                        updatedAirportJSONArray1 = updatedAirportJSONObject.getJSONArray("Airports");
                        noOfPages=updatedAirportJSONObject.getString("TotalPages");
                        System.out.println("no of pages:===========>"+noOfPages);
                        for(int l=0;l<updatedAirportJSONArray1.length();l++)
                        {
                            JSONObject tempJSONObject=updatedAirportJSONArray1.getJSONObject(l);
                            airportCode =tempJSONObject.getString("AirportCode");
                            airportName =tempJSONObject.getString("Name");
                            AirportModel airportModel=new AirportModel(airportCode,airportName);
                            airportArrayList.add(airportModel);



                        }
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
            return null;

    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        CustomListViewAdapter adapter1 = new CustomListViewAdapter(SearchAirportActivity.this,R.layout.airport_singlerow,airportArrayList);

        airportListView.setAdapter(adapter1);
    }

    @Override
    protected void onPreExecute() {

        super.onPreExecute();

    }

} 

I would go for increasing the List size dynamically. Load more items when user reaches to end of the List. as @RGraham suggested.

Android Endless List

Dynamically increasing the number of elements in a listview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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