@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RELOAD_LIST_CODE && resultCode == RESULT_OK) { NoticeBoard noticeBoard = (NoticeBoard) data.getSerializableExtra(NoticeBoard.class.getSimpleName()); if (noticeBoards.contains(noticeBoard)) { int index = noticeBoards.indexOf(noticeBoard); noticeBoards.set(index, noticeBoard); } else { noticeBoards.add(noticeBoard); adapter.notifyItemInserted(0); } adapter.notifyDataSetChanged(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); prepareActionBarToBack(getString(R.string.notice_board)); adapter = new NoticeBoardAdapter(NoticeBoardList.this, NoticeBoardList.this, noticeBoards); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(NoticeBoardList.this)); showProgressDialog(); WebFacade.retrieveListOfNoticeBoards( new WebFacade.QueryWebCallback<NoticeBoard>() { @Override public void onQueryResult(List<NoticeBoard> data, Exception e) { if (e == null) { noticeBoards.addAll(data); } else { noticeBoards.addAll(NoticeBoardDAO.retrieveAll()); } dismissProgressDialog(); adapter.notifyDataSetChanged(); } }); findViewById(R.id.fab) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(NoticeBoardList.this, NoticeBoardEntry.class); startActivityForResult(intent, RELOAD_LIST_CODE); } }); }