我正在使用EndlessAdapterCommonsware。当我添加了header视图时,我得到了listView,这得到了这个错误和LogCat

04-22 17:06:15.200: E/AndroidRuntime(6401): FATAL EXCEPTION: main
04-22 17:06:15.200: E/AndroidRuntime(6401): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
04-22 17:06:15.200: E/AndroidRuntime(6401):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at java.util.ArrayList.get(ArrayList.java:304)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.widget.ListView.dispatchDraw(ListView.java:3207)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.draw(View.java:13715)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.widget.AbsListView.draw(AbsListView.java:3653)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12650)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12588)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.View.getDisplayList(View.java:12694)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1198)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewRootImpl.draw(ViewRootImpl.java:2173)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.Choreographer.doFrame(Choreographer.java:532)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.os.Handler.handleCallback(Handler.java:725)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.os.Looper.loop(Looper.java:137)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at android.app.ActivityThread.main(ActivityThread.java:5226)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at java.lang.reflect.Method.invokeNative(Native Method)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at java.lang.reflect.Method.invoke(Method.java:511)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-22 17:06:15.200: E/AndroidRuntime(6401):     at dalvik.system.NativeStart.main(Native Method)


如果删除headerview,我将超越这一点。

补充:如果与标题视图无关,这是其他代码:

public class EndlessProfileAdapter extends EndlessAdapter implements
            IItemsReadyListener {

        private boolean hasMoreData = true;
        private RotateAnimation rotate = null;
        private View pendingView = null;
        private ArrayList<ProfileReview> profileList;

        public EndlessProfileAdapter(Context context,
                ArrayList<ProfileReview> profileList, Typeface tf) {
            super(new ProfileAdapter(context, profileList, tf));

            this.profileList = profileList;

            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 boolean cacheInBackground() throws Exception {
    Log.d("Cache Array Size", String.valueOf(profileList.size()));
    new ReviewTask(this, profileList.size()).execute();
    return hasMoreData;
}

@Override
protected void appendCachedData() {

}

void startProgressAnimation() {
    if (pendingView != null) {
        pendingView.startAnimation(rotate);
    }
}

public void onItemsReady(ArrayList<ProfileReview> data) {

    profileList.addAll(data);
    endlessAdapter.onDataReady();
    hasMoreData = profileList.isEmpty();
}


内部任务onPostExecute()

profileList = new ArrayList<ProfileReview>();

            for (int i = startPoint; i < startPoint + 10; i++) {
                ProfileReview p = new ProfileReview(itemIdList.get(i),
                        reviewIdList.get(i), reviews.get(i), datelist.get(i),
                        itemslist.get(i), ratings.get(i), cats.get(i));
                profileList.add(p);
            }

            return profileList;


EndlessAdapter在列表中以十个一组为一组。前10个工作...但是在11个工作时,它崩溃了。 LogCat崩溃实际上发生在第二个10轮(用户滚动到列表中的前10个后的第11项),并在profileList.add(p);之前崩溃

更新了请求的信息

onActivityCreated()内部:

       // for adapter constructor
       tf = Typeface.createFromAsset(getActivity().getAssets(),
            "fonts/listitemfont.ttf");


   LayoutInflater inflater = getActivity().getLayoutInflater();

    ViewGroup header = (ViewGroup) inflater.inflate(
            R.layout.profile_header, listView, false);

    listView = getListView();
    listView.addHeaderView(header, null, false);

            // stuff like settings up buttons inside header

            // just before end of  `onActivityCreated()`

        if (endlessAdapter == null) {
           if (getActivity() != null) {

            profileList = new ArrayList<ProfileReview>();
            endlessAdapter = new EndlessProfileAdapter(getActivity(),
                    profileList, tf);
            endlessAdapter.setRunInBackground(false);
            listView.setAdapter(endlessAdapter);
        }
    }

最佳答案

EndlessAdapter将无法支持页眉或页脚视图。使用页眉或页脚视图时创建的HeaderListViewAdapter对基础适配器进行一些假设,而EndlessAdapter并不总是这样。

我已经更新了EndlessAdapter文档以指出限制。

07-24 09:27