2016-08-16 15 views
-1

私のアプリケーションの一部では、私はRecyclerViewをカスタムダイアログに持っていますが、データを設定すると、Recyclerviewに保存され、新しいデータでリフレッシュされません。 :Android Recycle Recyclerview adapter on Dialog

transferred_to_user_history.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     List<Transactions> transactionsHistoryList = Collections.emptyList(); 
     transactionsHistoryList = realm.where(Transactions.class) 
       .equalTo("toUser", username) 
       .equalTo("destinationEwalletId", latestChosenUserEwallet) 
       .findAll(); 
     Log.e("transactionsHistoryList", transactionsHistoryList.size() + ""); 
     if (getChosenTransferredHistory == null) 
      getChosenTransferredHistory = 
        new GetChosenEwalletTransferredHistory(ActivityTransferMoney.this) 
        .setData(transactionsHistoryList); 

     getChosenTransferredHistory.setOnTransactiontHistory(new GetChosenEwalletTransferredHistory.IOnChooseTransactionHistory() { 
      @Override 
      public void getItem(EwalletsHistory item) { 
       getChosenTransferredHistory.dismissDialog(); 
       getChosenTransferredHistory = null; 
      } 
     }); 
     getChosenTransferredHistory.showDialog(); 
    } 
}); 

transactionsHistoryList.size()変数が最初で1を添付し、番組データをRecyclerViewにし、dismissDialog後、空の結果と再接続した場合、私は最後にShowDialog内のデータを添付した、

まずにShowDialog:

transactionsHistoryList.size(): 1 

第二にShowDialog:

transactionsHistoryList.size(): 0 

第二部では、私はrecylerview上のいくつかのデータを持っていますが、transactionsHistoryList.size()は私のカスタムダイアログ0

です:

public GetChosenEwalletTransferredHistory(ActivityTransferMoney context) { 
    this.context = context; 
    realm = realm.getDefaultInstance(); 

    dialog = new Dialog(context, R.style.theme_dialog); 
    dialog.setContentView(R.layout.dialog_user_transferred_history); 

    transferred_history = (RecyclerView) dialog.findViewById(R.id.transferred_history); 

    List<Transactions> r = new ArrayList<>(); 

    transferred_history.setLayoutManager(new LinearLayoutManager(context)); 
    adapter = new GetLatestUserTransferredHistoryAdapter(context, r); 
    transferred_history.setAdapter(adapter); 
} 

public GetChosenEwalletTransferredHistory setData(List<Transactions> result) { 
    adapter.setData(result); 
    adapter.notifyDataSetChanged(); 
    return this; 
} 

マイアダプタ:

public class GetLatestUserTransferredHistoryAdapter extends RecyclerView.Adapter<GetLatestUserTransferredHistoryAdapter.EwalletHistoryViewHolder> { 

    public static IOnItemClickListener iOnItemClickListener; 
    List<Transactions> list = Collections.emptyList(); 
    Context context; 

    public GetLatestUserTransferredHistoryAdapter(Context context, List<Transactions> list) { 
     this.list = list; 
     this.context = context; 
    } 

    @Override 
    public EwalletHistoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View      v  = LayoutInflater.from(parent.getContext()).inflate(R.layout.latest_transactions_items, parent, false); 
     EwalletHistoryViewHolder holder = new EwalletHistoryViewHolder(v); 
     return holder; 
    } 

    @Override 
    public void onBindViewHolder(EwalletHistoryViewHolder holder, final int position) { 
     holder.transaction_report_row.setText(list.get(position).getMoney() + list.get(0).getCurrencySymbol() + " on: " + list.get(position).getCreatedAt()); 
    } 

    @Override 
    public int getItemCount() { 
     return list.size(); 
    } 

    @Override 
    public void onAttachedToRecyclerView(RecyclerView recyclerView) { 
     super.onAttachedToRecyclerView(recyclerView); 
    } 

    public void setData(List<Transactions> list) { 
     this.list = list; 
    } 
} 
+0

getChosenTransferredHistory = nullを指定して更新されません。なぜあなたはこれをやっている? –

+0

@ColdFireそのためにダイアログを作成するための新しいインスタンスを作成します。アダプタが表示されないときにリフレッシュすると、ダイアログの新しいインスタンスを作成する必要があると思います –

答えて

0
public void setData(List<Transactions> list) { 
    this.list = list; 
} 

変化に:

public void setData(List<Transactions> list) { 
    this.list.clear(); 
    this.list.addAll(list); 
} 

リストは=