0

我正在尝试采用无尽的适配器。有一个活动 - 说 ClipsActivity 它扩展了抽象类,该抽象类扩展了 Activity。在一些例子中,我看到 Activity 是从 ListActivity 扩展而来的——这很重要吗?我还有一个扩展基本适配器的列表适配器,而在示例中使用了 ArrayAdapter。当我到达列表末尾时,我收到一个错误(下面的日志)

您是否介意指出问题可能是什么以及这种实施 Endless 的方式是否存在不确定性?另外,我将不胜感激有关详尽示例的链接。我看过演示 - 但对我来说还不够清楚。谢谢。

我的活动

public class ClipsActivity extends AbstractActivity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.clips);

            _init();
            ListView clipList = (ListView) findViewById(R.id.clipList);
            EndlessClipListAdapter endlessClipsList = new EndlessClipListAdapter(getApplicationContext(), new ClipListAdapter(this, _getClips()), R.id.downloadBar);
            clipList.setAdapter(endlessClipsList);
        } catch (HTTPFactoryException e) {
            e.printStackTrace();
        }
    }

我的无尽适配器

public class EndlessClipListAdapter extends EndlessAdapter {

    private RotateAnimation rotate=null;

    public EndlessClipListAdapter(Context context, ListAdapter wrapped, int pendingResource) {
        super(context, wrapped, pendingResource);
        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 {
        SystemClock.sleep(10000);
        return(getWrappedAdapter().getCount()<14);
    }

    @Override
    protected void appendCachedData() {
        if (getWrappedAdapter().getCount()<14) {
        }
    }

    @Override
    protected View getPendingView(ViewGroup parent) {
        //View row=getLayoutInflater().inflate(R.layout.row, null);
        //LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );

        LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );

        View row = inflater.inflate(R.layout.row, null);
        View child=row.findViewById(android.R.id.text1);

        child.setVisibility(View.GONE);

        child=row.findViewById(R.id.throbber);
        child.setVisibility(View.VISIBLE);
        child.startAnimation(rotate);

        return(row);
      }

}

日志猫

04-20 13:41:43.083: W/dalvikvm(480): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-20 13:41:43.093: E/AndroidRuntime(480): FATAL EXCEPTION: main
04-20 13:41:43.093: E/AndroidRuntime(480): java.lang.IndexOutOfBoundsException: Invalid index 15, size is 15
04-20 13:41:43.093: E/AndroidRuntime(480):  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
04-20 13:41:43.093: E/AndroidRuntime(480):  at java.util.ArrayList.get(ArrayList.java:311)
04-20 13:41:43.093: E/AndroidRuntime(480):  at ru.localhost.xxxx.android.view.ClipListAdapter.getItemId(ClipListAdapter.java:47)
04-20 13:41:43.093: E/AndroidRuntime(480):  at com.commonsware.cwac.adapter.AdapterWrapper.getItemId(AdapterWrapper.java:127)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:745)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:1088)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.widget.ListView.arrowScrollImpl(ListView.java:2324)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.widget.ListView.arrowScroll(ListView.java:2287)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.widget.ListView.commonKey(ListView.java:2089)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.widget.ListView.onKeyDown(ListView.java:2036)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.KeyEvent.dispatch(KeyEvent.java:1256)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.View.dispatchKeyEvent(View.java:3855)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:787)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.widget.ListView.dispatchKeyEvent(ListView.java:2021)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
04-20 13:41:43.093: E/AndroidRuntime(480):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
04-20 13:41:43.093: E/AndroidRuntime(480):  at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
04-20 13:41:43.093: E/AndroidRuntime(480):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.os.Looper.loop(Looper.java:123)
04-20 13:41:43.093: E/AndroidRuntime(480):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-20 13:41:43.093: E/AndroidRuntime(480):  at java.lang.reflect.Method.invokeNative(Native Method)
04-20 13:41:43.093: E/AndroidRuntime(480):  at java.lang.reflect.Method.invoke(Method.java:507)
04-20 13:41:43.093: E/AndroidRuntime(480):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-20 13:41:43.093: E/AndroidRuntime(480):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-20 13:41:43.093: E/AndroidRuntime(480):  at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

1

在一些例子中,我看到 Activity 是从 ListActivity 扩展而来的——这很重要吗?

不,欢迎您使用ListFragment,或使用 . 的普通活动ListView

我还有一个扩展基本适配器的列表适配器,而在示例中使用了 ArrayAdapter。

适配器需要支持附加附加数据的概念。ArrayAdapter做; CursorAdapter才不是。我不能说你的适配器是否会。

你介意指出问题可能是什么

我不确定。您实际上没有附加任何内容的事实appendCachedData()可能是候选人。请阅读文档并按照说明进行操作。

另外,我将不胜感激有关详尽示例的链接。

repo 中demo/子项目。

我看过演示 - 但对我来说还不够清楚。

这种模式在其他地方还有其他实现;也许其中一个组件会更适合您。

于 2012-04-20T14:47:19.083 回答