0

I have a problem with updating an item in RecycleView. When i try to edit a dream object and save it then it gets updated in database but not in the list of dream and I don't know why.

This method creates and updates a dream object.

@OnClick({R.id.addTagDream, R.id.saveDreamButton})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.addTagDream:
                Intent intent = new Intent(AddEditDreamActivity.this, SelectDreamActivity.class);
                startActivityForResult(intent, SELECTED_DREAM);
                break;
            case R.id.saveDreamButton:
                boolean hasError = false;
...

                    if (!hasError) {
    // check if exit dream about id 
                        try {
                            myDreamList = myDreamDao.queryForEq(MyDream.Columns.MY_DREAM_ID, dreamId);
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
    chcek if dream exist 
                        if (myDreamList != null && !myDreamList.isEmpty()) {

                            // update dream 

                            UpdateBuilder<MyDream, ?> updateMyDream = myDreamDao.updateBuilder();


// condition update dream about dream id 

                            try {
                                updateMyDream.where().eq(MyDream.Columns.MY_DREAM_ID, dreamId);
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
    // update column title dream 
                            try {
                                updateMyDream.updateColumnValue(MyDream.Columns.TITLE_DREAM, dreamTitle);
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
    // update dream description 
                            try {
                                updateMyDream.updateColumnValue(MyDream.Columns.DESCRIPTION, dreamDescription);
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
    // update dream symbol 
                            try {
                                updateMyDream.updateColumnValue(MyDream.Columns.SYMBOL_DREAM, selectSymbolDream);
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }

                            try {
                                updateMyDream.update();
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }

                            finish();
                        } 
                    }
                    break;
            }
        }
Pavneet_Singh
  • 34,557
  • 5
  • 43
  • 59
  • What is "dream" in your case? Also, your grammar needs work in this post. I suggest using Grammarly if you're not a native English speaker. – Ali Bdeir Oct 24 '17 at 16:28
  • 1
    Since the object is stored in the database, you need to set an action for the user that indicates that he wants to refresh the list. When he refreshes it, you update the list you're populating your RecyclerView with and then call `mAdapter.notifyDataSetChanged()` – Ali Bdeir Oct 24 '17 at 16:32
  • 1
    Possible duplicate of [How to update RecyclerView Adapter Data?](https://stackoverflow.com/questions/31367599/how-to-update-recyclerview-adapter-data) – Ali Bdeir Oct 24 '17 at 16:33

1 Answers1

1

Use adapter.notifyDataSetChanged() or notifyItemInserted() whenever you are adding values in list

Hope this will help you