我的活动包括recyclerview,我的数据设置为api调用的响应。我在api调用的成功响应中添加了以下代码。问题是当我点击按钮然后新列表刷新列表时因此,当我点击列表项时,多个活动打开,因为事件也被当前列表后面的列表占用。为什么会发生这种情况?我只是希望我的列表应该刷新新列表点击刷新按钮。我怎么解决这个问题?
@Override
public void onSuccess(ResponseData responseString) {
mAdapter = new RowAapter(responseString.getdatd(), mContext);
mList.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
mList.addOnItemTouchListener(new RecyclerItemClickListener(mContext, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
startActivity(...);
}
}));
答案 0 :(得分:0)
您可以初始化适配器并将其分配到OnCreate
private List<ResponseData> responseData = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail2);
mAdapter = new RowAapter(responseData , mContext);
recyclerView = ((RecyclerView)rootView.findViewById(R.id.recyclerView));
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(mAdapter);
}
@Override
public void onSuccess(ResponseData responseString) {
responseData.addAll(responseString.getdatd());
mAdapter.notifyDataSetChanged();
mList.addOnItemTouchListener(new RecyclerItemClickListener(mContext, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
startActivity(...);
}
}));