在我的应用程序的某些部分,我在自定义对话框上有RecyclerView
,但在我设置数据时,请保留在Recyclerview中并且不要刷新新数据,例如下面的代码是我的show custom Dialog:< / p>
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 :(得分:0)
public void setData(List<Transactions> list) {
this.list = list;
}
更改为:
public void setData(List<Transactions> list) {
this.list.clear();
this.list.addAll(list);
}
列表未使用=