@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
Toast.makeText(ViewPage.this, "In" , 1).show();
if (loading)
{
if (totalItemCount > previousTotal)
{
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold))
{
for(int i=0;i<5;i++)
{
filename[i] = contactcursor.getString(contact_column_index);
Toast.makeText(ViewPage.this, filename[i] +" "+ contactcursor.getString(contact_column_index) , 1).show();
contactcursor.moveToNext();
}
arr_ad = new ArrayAdapter<String>(ViewPage.this, android.R.layout.simple_list_item_1, filename);
setListAdapter(arr_ad);
// I load the next page of gigs using a background task,
// but you can call any function here.
// new LoadGigsTask().execute(currentPage + 1);
loading = true;
Toast.makeText(ViewPage.this,totalItemCount+" "+visibleItemCount+" "+firstVisibleItem+" "+visibleThreshold+" ", 1).show();
}
}
this is part of the code, where the onScroll should have worked only when listview was scrolled down, but it works automatically when activity starts as the toast within it is printed. thanx in advance.
First, you dont need to put toast in onScroll because its just not a good idea. Instead use
Log.Second, its called automatically because Listview needs to populate items inside. So when the ListView insert items for the first time, the scroll element is changed/updated too, causing onScroll to occur (i guess). Once the required amount of items are inserted to fill the Listview visible on screen, I think it will not raise onScroll. So its not a big issue.