作者:springaccounn | 来源:互联网 | 2023-05-28 06:55
我有一个包含列表视图的活动。当用户滚动到列表视图的底部时,列表将获取更多数据。当用户向下滚动时,滚动是平滑的。但是,当用户向上滚动时,列表视图倾向于将其可见项跳过一两个。
班级:
public class ListViewActivity extends Activity implements OnScrollListener {
int id = 0;
List dataParse = new ArrayList();
LazyAdapter adapter;
ListView listView;
List richArrayList = new ArrayList();
private int currentScrollState;
private int currentVisibleItemCount;
private int skipParam = 0;
private boolean flag_loading = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_list_list);
listView = (ListView) findViewById(R.id.listView);
// Need to create the adapter constructor
listView.setOnScrollListener(this);
adapter = new LazyAdapter(PostListActivity.this, dataParse, richArrayList);
listView.setAdapter(adapter);
setStory();
}
public void setStory() {
// Pull data from Parse
HashMap params = new HashMap();
params.put("userid", ParseUser.getCurrentUser().getObjectId());
params.put("skip", skipParam);
ParseCloud.callFunctionInBackground("studentsPosts", params, new FunctionCallback>>() {
@Override
public void done(List> data, com.parse.ParseException arg1) {
if (data == null) {
} else {
Log.e("size ", "RUNNING Size : " + data.size());
if (data.size() > 0) {
flag_loading = false;
for (int i = 0; i pFileList;
pFileList = (List) data.get(i).get(0).get("photos");
rc.setPhotosArray(pFileList);
}
if(data.get(i).get(0).getParseFile("photo") != null){
//Time to retrieve the photo
ParseFile getParseFile;
getParseFile = (ParseFile) data.get(i).get(0).get("photo");
//ParseFile getParseFile = ParseFile.this.getDataInBackground(data.get(i).get(0).getParseFile("photo"));
rc.setPhoto(getParseFile);
}
richArrayList.add(rc);
adapter.notifyDataSetChanged();
}
}
}
}
});
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
this.currentScrollState = scrollState;
this.isScrollCompleted();
}
private void isScrollCompleted() {
if (this.currentVisibleItemCount >= 5 && this.currentScrollState == SCROLL_STATE_IDLE) {
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
this.currentVisibleItemCount = visibleItemCount;
Log.e("firstVisibleItem", ""+firstVisibleItem);
Log.e("visibleItemCount", ""+visibleItemCount);
Log.e("totalItemCount", ""+totalItemCount);
if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount != 0) {
if (flag_loading == false) {
flag_loading = true;
Log.d("IN ON SCROLL", "NOW: " + skipParam);
skipParam = skipParam + 10;
setStory();
}
}
}
}
我要去哪里错了?为什么向上滚动会受到影响?