2017-10-24 15 views
0

RecycleViewでアイテムを更新する際に問題があります。 私は夢のオブジェクトを編集してそれを保存しようとするとデータベースに更新されますが、dreamのリストには含まれていません。理由はわかりません。RecyclerViewのオブジェクトを更新する

このメソッドは、夢のオブジェクトを作成して更新します。あなたは

希望リストに値を追加するたび

@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; 
      } 
     } 
+0

あなたのケースでは「夢」は何ですか?また、あなたの文法の必要性はこの投稿でも必要です。英語のネイティブスピーカーでなければ、文法を使うことをお勧めします。 –

+1

オブジェクトはデータベースに格納されているため、ユーザーがリストを更新する必要があることを示すアクションを設定する必要があります。彼がそれをリフレッシュすると、あなたはRecyclerViewを投入しているリストを更新してから、 'mAdapter.notifyDataSetChanged()'を呼び出します。 –

+1

[RecyclerViewアダプタのデータを更新する方法?](https://stackoverflow.com/questions/) 31367599/how-to-update-recyclerview-adapter-data) –

答えて

1

が使用adapter.notifyDataSetChanged()or notifyItemInserted()はこれがあなたを助ける

+0

私は夢を編集する必要があります – Programmer1993