8

如何插入overridePendingTransition`GridView适配器?以这种方式不起作用,没有过渡 startactivity 完美地工作

bt.setOnLongClickListener(new OnLongClickListener(){
                @Override
                public boolean onLongClick(View v) {
                        final String selectedPad = Drum.pads[position];
                        Intent modPad = new Intent(v.getContext(), ModifyPad.class);
                        modPad.putExtra("pad", selectedPad);
                        context.startActivity(modPad);
                        overridePendingTransition(R.anim.exit_slid_in, R.anim.exit_slid_out);
                    return false;
                }
            });

我读过这篇文章: android start Activity in adapter (transition animation direction problem) ,以及相关的评论,但我不知道如何通过Activity. Adapter有什么帮助吗?

4

1 回答 1

22

Context 是 Activity 的基础对象(参见:What is the difference between Activity and Context?),所以我使用了以下内容:

Activity activity = (Activity) mContext;
activity.startActivity(repinIntent);
activity.overridePendingTransition(R.anim.act_start_in_from_right, R.anim.act_start_out_to_left);

参考:在android中从上下文中获取activity

于 2013-07-29T15:38:50.360 回答