英文:
How to convert "apply" in this kotlin code to java?
问题
我需要将这段 Kotlin 代码转换为 Java,以便为 RecyclerView 设置 itemAnimator:
cardStackView.getItemAnimator().setSupportsChangeAnimations(false);
目前,我已经想到了以下类似的代码:
cardStackView.setItemAnimator(new DefaultItemAnimator() {
    @Override
    public void setSupportsChangeAnimations(boolean supportsChangeAnimations) {
        super.setSupportsChangeAnimations(supportsChangeAnimations);
    }
});
英文:
I need to convert this kotlin code to java to set the itemAnimator for a recylcer view
cardStackView.itemAnimator.apply {
        if (this is DefaultItemAnimator) {
            supportsChangeAnimations = false
        }
    }
So far i have come up with something like this:
cardStackView.setItemAnimator(new DefaultItemAnimator(){
             @Override
             public void setSupportsChangeAnimations(boolean supportsChangeAnimations) {
                                         super.setSupportsChangeAnimations(supportsChangeAnimations);
                   }
             }
    );
答案1
得分: 2
RecyclerView.ItemAnimator itemAnimator = cardStackView.getItemAnimator();
if (itemAnimator instanceof DefaultItemAnimator) {
    DefaultItemAnimator di = (DefaultItemAnimator) itemAnimator;
    di.setSupportsChangeAnimations(false);
}
英文:
RecyclerView.ItemAnimator itemAnimator = cardStackView.getItemAnimator();
        if (itemAnimator instanceof DefaultItemAnimator) {
            DefaultItemAnimator di = (DefaultItemAnimator) itemAnimator;
            di.setSupportsChangeAnimations(false);
        }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论