我使用此功能在2個活動之間切換時創建動畫。但它使我的應用程序停止(不會崩潰,就像暫停)。我從活動的片段中的適配器調用overridePendingTransition。爲什麼不重寫PendingTransition工作?
公共類LessonAdapter擴展RecyclerView.Adapter {
私有列表lessonList;
private Context 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,列表)對嗎? –
我有一個外面的課程列表,在片段中,我調用了getContext()。像這樣「LessonAdapter(getContext(),list)」 –
嘗試像這樣調用意圖Intent i = new Intent(getContext(),TenseLessonActivity.class); –