当我打算进行其他活动并按“后退”按钮时,回收者视图不会加载这些物品。或者,即使我切换了应用程序,回收者视图仍然无法加载项目。我尝试将宽度和高度更改为wrap_content
和match_parent
无效。
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_below="@+id/searchitembar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycler_products" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
我在展开式布局中使用了回收站视图 自定义适配器
viewHolder.expandableLayout.setInRecyclerView(false);
viewHolder.expandableLayout.setExpanded(expandState.get(position));
viewHolder.expandableLayout.setListener(new ExpandableLayoutListenerAdapter() {
@Override
public void onPreOpen() {
changeRotate(viewHolder.button,0f,180f).start();
expandState.put(position,true);
}
@Override
public void onPreClose() {
changeRotate(viewHolder.button,180f,0f).start();
expandState.put(position,false);
}
});
viewHolder.button.setRotation(expandState.get(position)?180f:0f);
viewHolder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.expandableLayout.toggle();
}
});
((ProductWithCategoryViewHolder) holder).product.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager= new LinearLayoutManager(context);
((ProductWithCategoryViewHolder) holder).product.setLayoutManager(layoutManager);
productAdapter= new ProductAdapter(tempproductlist,context,shop_id);
((ProductWithCategoryViewHolder) holder).product.setAdapter(productAdapter);
答案 0 :(得分:0)
如果您切换活动
val intent = Intent(Context,SecondActivityName::class.java)
startActivityForResult(mIntent,requestCode)
您需要使用startActivityForResult(mIntent, requestCode)
来打开第二活动,其中requestCode
是一些随机整数。
切换到第一个活动后 通过以下方法收到的回叫
override onActivityResult(requestCode: Int, resultCode: Int, data: Intent?{
if(requestCode = your provided integer){
//You update your recyclerview adapter here
RecyclerView.Adapter.notifyDataSetChanged()
}
}
如果您切换了应用,然后又回来刷新recyclerview
override onRestart(){
//You update your recyclerview adapter here
RecyclerView.Adapter.notifyDataSetChanged()
}