0

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();

    }

} 
Pradeep Negi
  • 1
  • 1
  • 3
  • I'm not sure whether I get you right, but you maybe should look into publishProgress and onProgressUpdate (in AsyncTask) in order to update your list after each item and not after all entries are processed...? – jpm Dec 06 '13 at 13:23
  • 5
    The best way to show 50,000 results is not to show 50,000 unless you *absolutely* need to. http://stackoverflow.com/questions/1080811/android-endless-list – CodingIntrigue Dec 06 '13 at 13:23

1 Answers1

2

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

Community
  • 1
  • 1
osayilgan
  • 5,873
  • 7
  • 47
  • 68