Reputation: 1155
Hi all i tried to implement the Endless list view from this website Endless list .I used this Endless listview to load 30 records from server for every hit.I am getting 30 records and added the records in the arraylist .The problem is when i tried to scroll down the listview it is not loading the new 30 records.But when i tried to scroll up list view is loading newly 30 records is added to the listview.Agin after when i scrolldown the next 30 records when i reach 60th record after that scroll down is working .But request is send and am getting 30 records from server and i added to my array list.When i scroll up am getting next 30 records and displaying in the list view.When i scroll down i should get 30 records .I had been spent more than 2 days still i can't figure out .Can any one tell me where am blocked.Thanks in advance.
list_Order.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) {
if(intPreviousFirstVisibleItem==firstVisibleItem)
return;
intPreviousFirstVisibleItem=firstVisibleItem;
int lastIndexInScreen = visibleItemCount + firstVisibleItem;
if (lastIndexInScreen>= totalItemCount && !isLoading)
{
intStartCount=intEndCount+1;
intEndCount=intStartCount+29;
strStartCount=Integer.toString(intStartCount);
strEndCount=Integer.toString(intEndCount);
new LoadDataFromServer().execute(strStartCount, strEndCount);
adapter.notifyDataSetChanged();
}
}
});
//Class LoadDataFromServer
class LoadDataFromServer extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(context);
pDialog.setMessage("Please wait...");
isLoading=true;
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... args)
{
String response=null;
try
{
if (args.length >= 1) {
strStartCount = args[0];
strEndCount = args[1];
}
else
{
strStartCount = "0";
strEndCount = "1";
}
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
String studioID=Globals.getStr_Studio_ID();
String modifiedUrl= studioOrderDetailseUrl.concat("/").concat(studioID).concat("/").concat("all").concat("/").concat(strStartCount).concat("/").concat(strEndCount);
HttpGet httpGet = new HttpGet(modifiedUrl);
httpResponse = httpClient.execute(httpGet);
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
if(response!=null)
{
JSONObject jsonObj = new JSONObject(response);
jsArray_contacts=jsonObj.getJSONArray("GetStudioManDataResult");
for(int i=0;i<jsArray_contacts.length();i++)
{
JSONObject jsob = jsArray_contacts.getJSONObject(i);
String orderName=jsob.getString("CustomerName");
String orderID=jsob.getString("OrderId");
String orderAmount=jsob.getString("FinalAmount");
String mobileNumber=jsob.getString("MobileNo");
DecimalFormat df = new DecimalFormat("0.00");
double value = Double.parseDouble(orderAmount);
orderAmount="Rs."+df.format(value);
year = Calendar.getInstance().get(Calendar.YEAR)%100;
strYear=Integer.toString(year);
intOrderID=Integer.parseInt(orderID);
formatedOrderID = String.format("%04d", intOrderID);
orderID="OD".concat(strYear).concat(formatedOrderID);
strOrderName.add(orderName);
strOrderId.add(orderID);
strOrderAmount.add(orderAmount);
strMobileNumber.add(mobileNumber);
}
if( strOrderId.size()>=1){
for(int i=0;i<strOrderId.size();i++){
str_Order_Amount=strOrderAmount.get(i);
str_Oder_ID=strOrderId.get(i);
str_Customer_number=strMobileNumber.get(i);
str_Customer_Name=strOrderName.get(i);
Customers_Orders_Bean cob = new Customers_Orders_Bean(str_Oder_ID, str_Customer_number, str_Customer_Name, str_Order_Amount);
customerlist.add(cob);
}
}
}
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
}
catch(IOException e)
{
}
catch(NullPointerException e)
{
System.out.println("All_Order_Asyntask:NullPointer"+e.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
System.out.println("Inside the ALL -Order-POST()");
// setCustList();
//list_Order.setAdapter(new CustomizeOrderListAdapter(context,strOrderId, strOrderName,strOrderAmount,strMobileNumber));
if(pDialog.isShowing())
{
pDialog.dismiss();
}
adapter.notifyDataSetChanged();
isLoading=false;
}
}
Upvotes: 0
Views: 66
Reputation: 2916
Most likely this is your problem:
new LoadDataFromServer().execute(strStartCount, strEndCount);
adapter.notifyDataSetChanged();
If
new LoadDataFromServer()
is an AsyncTask, you should notifyDataSetChanged in its onPostExecute method.
At the moment, you notify directly after starting the task (and before the new data is loaded). You won't see the new data until you scroll again and notifydatasetchanged is called again.
Upvotes: 1