如何在android java中的数据绑定recyclerview适配器中创建2列

阴影

我知道通常通过 GridLayoutManager 做什么,但因为我一直在使用 Google 的 GithubBrowserSample (Java),但我无法使用此方法复制该过程。

尝试更改 xml 的跨度计数,但我使用的是 androidx 版本并且似乎没有打球

我的主要片段:

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    categoryViewModel = ViewModelProviders.of(this, viewModelFactory).get(CategoryViewModel.class);
    refreshAndObserve();
    CategoryListAdapter cvAdapter = new CategoryListAdapter(dataBindingComponent);
    binding.get().categoryList.setAdapter(cvAdapter);
    adapter = new AutoClearedValue<>(this, cvAdapter);
}

我的适配器:

public class CategoryListAdapter extends DataBoundListAdapter<Category, ListItemCategoryBinding> {
private final androidx.databinding.DataBindingComponent dataBindingComponent;

public CategoryListAdapter(DataBindingComponent dataBindingComponent) {
    this.dataBindingComponent = dataBindingComponent;
}

@Override
protected ListItemCategoryBinding createBinding(ViewGroup parent) {
    ListItemCategoryBinding binding = DataBindingUtil
            .inflate(LayoutInflater.from(parent.getContext()), R.layout.list_item_category,
                    parent, false, dataBindingComponent);
    return binding;
}
  }

谢谢你。

阴影

这似乎可以通过 XML 来完成:

app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

适配器中的Android RecyclerView显示问题

如何在recyclerView的适配器中调用scrollToPosition(position)?

如何更新RecyclerView适配器数据?

如何从Android中的RecyclerView适配器获取物品

如何在Android中自定义适配器?

如何从RecyclerView适配器返回数据?

如何在片段中调用RecyclerView适配器的方法

如何清除RecyclerView适配器数据

RecyclerView适配器中的数据绑定-Android

如何在Android的适配器中设置数据

如何使用Recyclerview中单击的适配器位置获取数据?

如何从片段中的RecyclerView适配器启动活动

如何在同一recyclerview的适配器类中更新recyclerview?

到recyclerview的Firebase数据显示错误-RecyclerView:android中未连接适配器

如何从Android Kotlin中的RecyclerView适配器获取arraylist

如何在其适配器中刷新android listview

addAll如何在Android List适配器中工作?

如何从MobileFirst Platform 7.0中的JS适配器过程调用Java适配器过程?

如何在Android适配器中传递Json数据

如何在RecyclerView适配器的onBindViewHolder中声明overridePendingTransition?

如何在其适配器的onBindViewHolder中更新recyclerView?

如何在分段适配器(Android)中获得位置?

Android-在Listview中显示来自适配器的数据

如何在 OnSuccessListener 中的 recyclerview 适配器中传递侦听器

库模块中的 Android RecyclerView 适配器

Android - 在数据绑定适配器中传递视图

如何为 Android 中的 2 路数据绑定制作合适的绑定适配器

如何在 recyclerview 适配器中与 Viewmodel 交互?

android - 在 RecyclerView 适配器中创建和使用 ViewBinder