小编ami*_*udi的帖子

动态更改视图类型RecylerView

我想通过单击底部更改所有项目Views RecyclerView。我只更改视图类型变量并调用notifyDataSetChanged() 以通知适配器,但不进行任何更改

private void ChangeAdapterView(){

    if (viewType==0) {
        StuffAdapter.ViewType=++viewType;
        recyclerView.getAdapter().notifyDataSetChanged();
    }
    else if (viewType==1){
        viewType=0;
        StuffAdapter.ViewType=viewType;
        recyclerView.getAdapter().notifyDataSetChanged();
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:我使用灵活的布局,不需要更改跨度大小,我只想更改视图

public class StuffAdapter extends RecyclerView.Adapter< StuffAdapter.ViewHolder> {

private final Realm realm;
private final String base;
public  static int ViewType=0;

    public static void setViewType(int viewType) {
        ViewType = viewType;
    }

    Picasso picasso;
    Context context;
    StoreView communicator;
    SessionManager sessionManager;
    List<StuffPOJO> data;
    int sellerId;
    public StuffAdapter(@Nullable List<StuffPOJO> data,
                        Picasso picasso, Context context,StoreView communicator) {
        this.context=context;
        this.picasso=picasso;
        this.data=data;
        base=context.getResources().getString(R.string.base_url);
        this.communicator=communicator;
        sessionManager=new …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
144
查看次数

标签 统计

android ×1