1

我正在EndlessAdapter使用Commonsware. 当我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);
        }
    }
4

1 回答 1

1

EndlessAdapter将无法支持页眉或页脚视图。当HeaderListViewAdapter您使用页眉或页脚视图时创建的 对底层适配器进行了一些假设,而EndlessAdapter.

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

于 2013-04-23T14:59:55.693 回答