This is My main Class
public class EndlessAdapterDemo extends Activity {
private ListView mListView;
private ProgressDialog dialog;
private OutletsXmlHandler mOutletXmlHandler;
private FetchAndParseData getDownloadedData;
private OutletListAdapter mOutletListAdapter;
public InputStream inputStream;
private ArrayList<Outlets> outletList;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.list_tab);
mListView = (ListView) findViewById(R.id.listView1);
mOutletXmlHandler = new OutletsXmlHandler();
dialog = new ProgressDialog(this);
dialog.setMessage("Loading");
dialog.setCancelable(false);
new MyTask().execute();
}
}
**And in MyTask class i am doing following**
public class MyTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
getDownloadedData = (FetchAndParseData) new FetchAndParseData().execute("http://184.106.222.195/zootapi/index.php/api/outlets/searchoutlets/token/something/cityid/83/parameters/&cu=American&s=Air$Conditioned");
inputStream = getDownloadedData.get();
XmlUtilities.parseAndLoadData(inputStream , mOutletXmlHandler);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
outletList = Project.getOutletList();//Project.getOutletList();
mListView.setAdapter(new DemoAdapter(outletList));
if(dialog.isShowing()){
dialog.dismiss();
}
}
}
**Now in this Demo Adpapter i am extending it with EndlessAdpater**
class DemoAdapter extends EndlessAdapter {
private RotateAnimation rotate=null;
DemoAdapter(ArrayList<Outlets> outletList) {
super(new OutletListAdapter(EndlessAdapterDemo.this, outletList));
rotate=new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotate.setDuration(600);
rotate.setRepeatMode(Animation.RESTART);
rotate.setRepeatCount(Animation.INFINITE);
}
@Override
protected View getPendingView(ViewGroup parent) {
View row=getLayoutInflater().inflate(R.layout.row, null);
View child=row.findViewById(android.R.id.text1);
child.setVisibility(View.GONE);
child=row.findViewById(R.id.throbber);
child.setVisibility(View.VISIBLE);
child.startAnimation(rotate);
return(row);
}
@Override
protected boolean cacheInBackground() {
try {
getDownloadedData = (FetchAndParseData) new FetchAndParseData().execute("http://184.106.222.195/zootapi/index.php/api/outlets/fetchoutlets/token/something/cityid/76/verticalid/1");
inputStream = getDownloadedData.get();
XmlUtilities.parseAndLoadData(inputStream , mOutletXmlHandler);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
@Override
protected void appendCachedData() {
outletList = Project.getOutletList();//Project.getOutletList();
mListView.setAdapter(new DemoAdapter(outletList));
}
}
**Now in this Source Code when the list reaches at the end the data is loaded successfully into the list view from web service bt previous data had been lost..
can anyone please help me… i am in deep trouble in this
**
You are creating a new DemoAdapter each time.
Change your appendCachedData to get the wrappered adapter and then add your extra elements to it: