这可能是一个简单的问题,但我已经浪费了几个小时。我希望在从 Backendless 加载数据后,在加载整个列表的不同时间之后,“需要加载更多”功能无法访问进度对话框。
这是我的代码
adapter = new MainAdapter( MainActivity.this, R.layout.main_row_item, totalMains );
setListAdapter( adapter );
QueryOptions queryOptions = new QueryOptions();
queryOptions.setRelated( Arrays.asList( "message" ) );
BackendlessDataQuery query = new BackendlessDataQuery( queryOptions );
Backendless.Data.of( Main.class ).find( query, new LoadingCallBack<BackendlessCollection<Main>>( this, getString( R.string.loading_mains ), true )
{
@Override
public void handleResponse( BackendlessCollection<Main> mainsBackendlessCollection )
{
mains = mainsBackendlessCollection;
addMoreItems( mainsBackendlessCollection );
super.handleResponse( mainsBackendlessCollection );
}
} );
ListView list = (ListView) findViewById( android.R.id.list );
list.setOnScrollListener( new AbsListView.OnScrollListener()
{
@Override
public void onScrollStateChanged( AbsListView view, int scrollState )
{
}
@Override
public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount )
{
if( needToLoadItems( firstVisibleItem, visibleItemCount, totalItemCount ) )
{ progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("正在加载更多数据请稍候..."); progressDialog.setIndeterminate(false); progressDialog.setCancelable(true);progressDialog.show();
isLoadingItems = true;
mains.nextPage( new LoadingCallBack<BackendlessCollection<Main>>( MainActivity.this )
{
@Override
public void handleResponse( BackendlessCollection<Main> nextPage )
{
progressDialog.dismiss();
mains = nextPage;
addMoreItems( nextPage );
isLoadingItems = false;
}
} );
}
}
} );
}
private boolean needToLoadItems( int firstVisibleItem, int visibleItemCount, int totalItemCount )
{
return !isLoadingItems && totalItemCount != 0 && totalItemCount - (visibleItemCount + firstVisibleItem) < visibleItemCount / 2;
}
private void addMoreItems( BackendlessCollection<Main> nextPage )
{
totalMains.addAll( nextPage.getCurrentPage() );
adapter.notifyDataSetChanged();
}
}
我是安卓新手。。