我正在使用Recyclerview。我想从其持有者完成当前活动。当我点击项目我想要打开新活动并完成当前活动。请帮助 我的代码如下所示。
public class GcmNotificationHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
protected TextView gcmMessage;
protected TextView messageTital;
protected TextView messageDate;
protected ImageButton removeMessage;
protected Context context;
protected List<Notification> notificationList;
protected boolean isRead = true;
public GcmNotificationHolder(View itemView, List<Notification> notificationList, Context applicationContext) {
super(itemView);
itemView.setOnClickListener(this);
context = applicationContext;
this.gcmMessage = (TextView)itemView.findViewById(R.id.gcmMessage);
this.messageTital=(TextView)itemView.findViewById(R.id.messagTital);
this.messageDate=(TextView)itemView.findViewById(R.id.gcmMessageDate);
this.notificationList = notificationList;
}
@Override
public void onClick(View v) {
Intent intent = new Intent(context.getApplicationContext(), NotificationDescriptionActivity.class);
intent.putExtra("messageDescription", notificationList.get(getAdapterPosition()).getMessage());
intent.putExtra("messageTital", notificationList.get(getAdapterPosition()).getMessagetital());
intent.putExtra("messageDate", notificationList.get(getAdapterPosition()).getMessagedate());
notificationList.get(getAdapterPosition()).getId();
notificationList.get(getAdapterPosition()).setIsRead(true);
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "notification-db", null);
SQLiteDatabase db = helper.getWritableDatabase();
DaoMaster daoMaster = new DaoMaster(db);
DaoSession daoSession = daoMaster.newSession();
NotificationDao notificationDao = daoSession.getNotificationDao();
notificationDao.updateInTx(notificationList);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}}
答案 0 :(得分:1)
当我在holder Constructor中传递Activity实例时,它解决了我的问题
答案 1 :(得分:1)
只需在onClick()的末尾添加下一行:
{{1}}