gpt4 book ai didi

android - ViewPager fragment 中的 RecyclerView 不显示

转载 作者:太空狗 更新时间:2023-10-29 16:34:26 25 4
gpt4 key购买 nike

所以我有一个 fragment ,它有一个带有 tablayout 的 viewpager,它由两个选项卡 - 两个 fragment 组成。

问题是,recyclerview 显示为空,我不知道为什么。,

标签 fragment 布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

标签 fragment :

List<OrderListItem> orderList = new ArrayList<>();
orderList.add(new OrderListItem(333, "ABCDE", new Date(), new Date(), false, true));

adapter = new OrderListAdapter(orderList, this.getActivity());
layoutManager = new LinearLayoutManager(this.getActivity(), LinearLayoutManager.VERTICAL, false);
myRecyclerView.setLayoutManager(layoutManager);
myRecyclerView.setAdapter(adapter);

适配器:

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

private List<OrderListItem> orderList;
@LayoutRes
private final int layoutRes;

private Context context;
private final LayoutInflater inflater;

public OrderListAdapter(List<OrderListItem> orderList, Context context){
this.orderList = orderList;
this.layoutRes = R.layout.order_list_item_layout;
this.context = context;
inflater = LayoutInflater.from(this.context);
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(layoutRes, parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final OrderListItem item = orderList.get(position);
}

public void setItems(List<OrderListItem> orderList){
this.orderList.clear();
this.orderList.addAll(orderList);
notifyDataSetChanged();
}

@Override
public int getItemCount() {
return orderList.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder {

public ViewHolder(View itemView) {
super(itemView);

}
}
}

RecycleView Item 一些丰富多彩的布局内幕,所以我知道子布局是否存在,它不存在。知道为什么 recyclerview 是空的吗?

edit1:我知道 recyclerview 在那里,因为它在 lolipop 手机中,如果我在回收站位置移动,它会显示波纹顶部和底部滚动边框。但是子布局是空的,应该是彩色的,正如我在子布局中指定的那样。

eit2。刚刚使用带有 simpleAdapter 的 ListView ,它正在显示。房车一定有问题

edit3:行布局(除了没有设置任何值之外,我应该清楚地看到一个带有颜色的空 TextView 。)

<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/black"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_deep_teal_200"
android:text="New Text"
android:id="@+id/textView" />
</LinearLayout>

最佳答案

改变:

android:layout_width="match_parent"
android:layout_height="match_parent"

android:layout_width="50dp"  // set yourself
android:layout_height="50dp" // set yourself

关于android - ViewPager fragment 中的 RecyclerView 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32379026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com