2つのアクティビティを切り替えるときにこの関数を使用してアニメーションを作成します。しかし、それは私のアプリを停止させる(一時停止のようなクラッシュではない)。私は、アクティビティのフラグメント内のアダプタからoverridePendingTransitionを呼び出します。overridePendingTransitionはなぜ機能しませんか?
パブリッククラスLessonAdapterはRecyclerView.Adapter {
プライベートリストlessonListを拡張します。
プライベートコンテキストmContext;
public LessonAdapter(Context context, List<Lesson> ll) {
lessonList = ll;
mContext = context;
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.lesson_card,parent, false);
return new LessonHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
final LessonHolder lessonHolder = (LessonHolder) holder;
lessonHolder.lessonName.setText(lessonList.get(position).getLessonName());
lessonHolder.lessonName.setTextColor(Color.parseColor("#0B8E46"));
lessonHolder.lessonDescription.setText(lessonList.get(position).getLessonDescription());
lessonHolder.lessonDescription.setTextColor(Color.parseColor("#686868"));
if (lessonList.get(position).getUuid() == 1) {
lessonHolder.lessonCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, WordTypeLessonActivity.class);
mContext.startActivity(i);
((Activity) mContext).overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
});
}
if (lessonList.get(position).getUuid() == 2) {
lessonHolder.lessonCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, TenseLessonActivity.class);
mContext.startActivity(i);
((Activity) mContext).overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
});
}
if (lessonList.get(position).getUuid() > 2) {
lessonHolder.lessonCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, LessonActivity.class);
i.putExtra("lesson_id", lessonList.get(position).getUuid());
mContext.startActivity(i);
((Activity) mContext).overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
});
}
}
@Override
public int getItemCount() {
return lessonList.size();
}
}
すべてのことが正しいようですが、このLessonAdapter(getActivity、list)のようなコンテキストをどうやって渡しますか? –
私はレッスンのリストを外に持っていますが、フラグメントでは、私はgetContext()を呼び出します。このように "LessonAdapter(getContext()、list)" –
このようなインテントを呼び出そうとすると、i = new Intent(getContext()、TenseLessonActivity.class); –