1
我已經創建了一個回收視圖視圖,它將具有cardView行,在卡片視圖中,我已經放置了一個佈局,點擊它後,一個childview將打開,當我點擊佈局時,子視圖即將到來,但數據是已經填充在卡上消失。而當我向下滾動子視圖本身消失,卡上的數據再次填充。我很長一段時間無法找到解決方案,請幫助我這個。This是我如何在適配器爲什麼當我點擊同一行的子視圖時,行上的Recycler視圖數據不見了?
@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方法中添加子視圖,因爲我需要傳遞上下文並獲取回收器視圖和適配器的引用,請執行以下操作?@peeyush pathak – yacky
您將在適配器中擁有上下文,因爲您正在使用它在onCreateViewHolder中,因爲你必須膨脹一個新的視圖。 –