当ExpandableListView实现OnScrollListener后处理分页问题,但是加载数据后怎么让数据向下滚动一段距离,因为重新加载后每次看到的内容都是第一条。
expandList.setOnScrollListener(new AbsListView.OnScrollListener() {
/**
* 当滚动状态发生改变时 调用此方法
* 参数1:当前的ListView
* 参数2:ListView 滚动状态
* scrollState:
* SCROLL_STATE_IDLE:停止滚动的状态 常量值 0
* SCROLL_STATE_TOUCH_SCROLL:正在滚动 手指还在屏幕上 常量值 1
* SCROLL_STATE_FLING :代表滚动 形成惯性的动作 常量值 2
*
*/
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
LogUtils.e("=onScrollStateChanged=",scrollState + "");
if(isLast&&scrollState ==SCROLL_STATE_IDLE){
Toast.makeText(getContext(), "下拉加载更多", Toast.LENGTH_SHORT).show();
pageIndex++;
LogUtils.e("=pageIndex=",pageIndex + "");
initDatas();
//TODO 让列表滑动
}
if(isLast == false &&scrollState ==SCROLL_STATE_IDLE) {
Toast.makeText(getContext(), "上拉查找最新", Toast.LENGTH_SHORT).show();
}
}
/**
* 当前控件滚动时 调用此方法
* 参数1:当前的ListView
* 参数2:当前屏幕展示第一条能看到的item的下标
* 参数3:屏幕展示能看到item的条数
* 参数4:listVIew 总的item数
*/
@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {
LogUtils.e("=onScroll=",i + "--" + i1 + "--" +i2);
isLast = ((i+i1)==i2);
LogUtils.e("=isLast=",isLast+"");
}
});
protected void initDatas() {
LogUtils.e("=1=","initDatas:");
if (NetUtils.isConnected(this.getContext())) {
new getChapterListConn().execute();
} else {
//NoNetAdapter();
ToastUtil.showShort(this.getContext(), R.string.net_notConnectedHint);
}
}
class getChapterListConn extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... strings) {
String url = HttpConstant.getChapterListConn;
TRSectionQuestionRelationCriteria criteria = new TRSectionQuestionRelationCriteria();
criteria.setSectionId(studentId);
criteria.setCourse(course);
criteria.setGrade(grade);
criteria.setPageNo(pageIndex);
criteria.setPageSize(pageSize);
String postString = JsonUtils.javaBeanToJson(criteria);
//String postString = "studentId="+studentId+"&course="+course+"&grade="+grade+"&pageNo="+pageIndex+"&pageSize="+pageSize;
LogUtils.e("postString:" , postString);
String json = HttpConnectionUtil.AccessUrl(url,postString);
LogUtils.e("json:" , json);
return json;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
ApiResponse<TRSectionQuestionRelation> info = JsonUtils.jsonToJavaBean(result, ApiResponse.class);
if (info.getCode() != null && info.getCode().equals("10000")) {
list = JsonUtils.jsonToJavaBeanList(JSONArray.toJSONString(info.getData()), TRSectionQuestionRelation.class);
if(list != null && list.size() > 0) {
alllist.addAll(list);
mAdapter = new SectionQuestionRelationAdapter(getContext(), alllist);
expandList.setAdapter(mAdapter);
//默认展开子列表
for(int i = 0; i < mAdapter.getGroupCount(); i++){
expandList.expandGroup(i);
}
//listView.setAdapter(mAdapter);
}
}
}
}