0

我尝试为我的单个项目设置动画ListView,我发现这有点难。但是,经过一番谷歌搜索后,我想出了一些合并的代码片段,但是当我尝试调用我ListView的 'sgetChildAt以返回视图时,它返回 null。

public void animateSingleItemInListView() {
        final Animation animBounce = AnimationUtils.loadAnimation(context, R.anim.bounce);
        int totalItemsInListView = lastCases.getCount();
        int wantedPosition = 1; // Whatever position you're looking for
        int firstPosition = lastCases.getFirstVisiblePosition() - lastCases.getHeaderViewsCount(); // This is the same as child #0
        int wantedChild = wantedPosition - firstPosition;
        // Say, first visible position is 8, you want position 10, wantedChild will now be 2
        // So that means your view is child #2 in the ViewGroup:
        int childs = lastCases.getChildCount();
        if (wantedChild < 0) {
          Log.w("UPDATEUI", "Unable to get view for desired position, because it's not being displayed on screen.");
          return;
        }
        // Could also check if wantedPosition is between listView.getFirstVisiblePosition() and listView.getLastVisiblePosition() instead.
        View wantedView = lastCases.getChildAt(firstPosition);
        wantedView.setAnimation(animBounce);
    }

从代码:

返回 10,这totalItemsInListView是 my 中正确的行数ListView。整数firstPosition当然是0,但是getChildAt()方法只返回n​​ull。怎么来的?我怎样才能得到我的第View一个ListView

4

1 回答 1

-1

尝试使用

lastCases.getItemAtPosition(firstPosition)
于 2013-01-08T10:50:19.557 回答