0

我正在尝试使用Niek Haarman 的ListViewAnimations库。我正在尝试将外观动画与包含 xml 行的列表视图一起使用。wiki 中使用的示例是针对一行 TextViews 的,我正在尝试对其进行修改,但没有取得多大成功。

来自文本视图的工作示例的代码:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getListView().setDivider(null);

        MyAdapter adapter = new MyAdapter();

        // Create an Animation adapter, wrapping the origional one

        SwingBottomInAnimationAdapter antAdapter = new SwingBottomInAnimationAdapter(adapter);

        // Stack another animation in from the bottom

        SwingRightInAnimationAdapter test2 = new SwingRightInAnimationAdapter(antAdapter);


        test2.setAbsListView(getListView());


        setListAdapter(test2);

        for (int i = 0; i < 50; i++){
            adapter.add("This is row number: " + String.valueOf(i));
        }

    }

    private class MyAdapter extends ArrayAdapter <String>{

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            TextView tv = (TextView) convertView;
            if (tv == null){
                tv = new TextView (MainActivity.this);
            }

            tv.setText(getItem(position));

            return tv;
        }

    }

}

这是我的代码中的一个示例,来自 fillData 方法(我的数据是从内容提供者中提取的):

private void fillData() {

    // Pulls the fields from the database and assigns them to the columns

    String[] from = new String[] { BorrowMeTable.COLUMN_ITEM,
            BorrowMeTable.COLUMN_NAME, BorrowMeTable.COLUMN_DATE, BorrowMeTable.COLUMN_IMAGE };

    // The label for each textview
    int[] to = new int[] { R.id.label, R.id.pName, R.id.pDate, R.id.icon };

    //getLoaderManager().initLoader(0, null, this);
    adapter = new SimpleCursorAdapter(this, R.layout.bm_row, null, from,
            to, 0);

    adapter.setViewBinder(new MyViewBinder()); // Add Viewbinder to allow the BLOB data as a picture

    // ADDED THIS ---- >>>>
    SwingBottomInAnimationAdapter antAdapter = new SwingBottomInAnimationAdapter(adapter);

    // ADDED THIS
    getListView().setAdapter(antAdapter);

    // ADDED THIS ----- >>>>
    setListAdapter(antAdapter);

    getLoaderManager().initLoader(0, null, this);
}

这是我收到的错误消息:

11-10 21:17:29.588: E/AndroidRuntime(870): java.lang.IllegalStateException: Call setListView() on this AnimationAdapter before setAdapter()!
11-10 21:17:29.588: E/AndroidRuntime(870):  at com.haarman.listviewanimations.swinginadapters.AnimationAdapter.getView(AnimationAdapter.java:121)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.AbsListView.obtainView(AbsListView.java:2177)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1247)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.ListView.onMeasure(ListView.java:1159)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.View.measure(View.java:15848)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.View.measure(View.java:15848)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.View.measure(View.java:15848)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
11-10 21:17:29.588: E/AndroidRuntime(870):  at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:302)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.View.measure(View.java:15848)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-10 21:17:29.588: E/AndroidRuntime(870):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.View.measure(View.java:15848)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.Choreographer.doFrame(Choreographer.java:532)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.os.Handler.handleCallback(Handler.java:730)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.os.Looper.loop(Looper.java:137)
11-10 21:17:29.588: E/AndroidRuntime(870):  at android.app.ActivityThread.main(ActivityThread.java:5103)
11-10 21:17:29.588: E/AndroidRuntime(870):  at java.lang.reflect.Method.invokeNative(Native Method)
11-10 21:17:29.588: E/AndroidRuntime(870):  at java.lang.reflect.Method.invoke(Method.java:525)
11-10 21:17:29.588: E/AndroidRuntime(870):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-10 21:17:29.588: E/AndroidRuntime(870):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-10 21:17:29.588: E/AndroidRuntime(870):  at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

1

adapter.add() 方法是库中存在的数组适配器的自定义方法,从库中导入数组适配器(com.haarman.listviewanimations.ArrayAdapter)以使用此方法并确保传递元素列表或在你的情况下给构造函数一个空列表

于 2014-01-18T18:25:48.537 回答