[英]Why is Recycler view data on the row is gone when i click on the same row's child view?
我创建了一个回收者视图视图,该视图将具有cardView行,在Card View中,我放置了一个布局,单击它会打开一个childview,当我单击布局时,将出现child view,但是已经填充的数据向下滚动时,子视图本身消失,并且再次填充了卡上的数据。很长时间以来我一直无法找到解决方案,请为此提供帮助。我在适配器中添加了子视图
@Override
public void onClick(View view) {
mAdapter = new ViewOrderAdapter(orderList);
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// view = inflater.inflate(R.layout.cancelledcardview, null);
final RelativeLayout parent = (RelativeLayout) inflater.inflate(R.layout.cancelledcardview, null);
Log.i("TAG", "onclickmethod" + parent);
final View child = inflater.inflate(R.layout.vieworder_layout, null);
recyclerView = (RecyclerView)child. findViewById(R.id.recycler_view);
Log.i("TAG", "onclickmethod" + recyclerView);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(mAdapter);
parent.addView(child);
ImageView cancelButton= (ImageView)child.findViewById(R.id.cancelbutton);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("TAG", "onclickmethodcancel button" );
parent.removeView(child);
}
});
prepareMovieData();
cv.addView(parent);
}
您必须保持点击状态。 滚动列表时,将再次调用onBind方法,并再次填充旧卡。 我建议-在模型中再创建1个变量(isClicked),并在单击时将其设置为true。 -在适配器的onBind方法中,您必须再次编写用于创建此子视图的代码。
或者您可以使用ExpandableListView,这将更优雅地处理状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.