[英]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.