2015-09-03 96 views
1

所以我有一個片段,它有一個tablayout viewpager,它由兩個選項卡 - 兩個片段組成。RecyclerView裏面ViewPager片段不顯示

的事情是,recyclerview顯示空的,我不知道爲什麼,

標籤片段佈局:

<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> 

標籤片段:

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); 

     } 
    } 
} 

Recy cleView項目一些豐富多彩的佈局內幕,所以我知道如果孩子佈局是否存在,它不是。任何想法爲什麼recyclerview是空的?

edit1:我知道recyclerview在那裏,因爲它在一個lolipop手機中,並且如果我在回收站進行移動,它會向我顯示波紋頂部和底部滾動邊界。但孩子的佈局是空的和空白的,應該是多彩的,因爲我在孩子的佈局中具體化。

eit2。只是用一個簡單的適配器的列表視圖,它正在顯示。一定有什麼車與休旅車

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> 

回答

2

哪裏是在其中設置邏輯OrderListItem屬性爲ui? 你必須先設置ViewHolder組件:

public static class ViewHolder extends RecyclerView.ViewHolder { 
    TextView mTitleTv; 
    public ViewHolder(View itemView) { 
     super(itemView); 
     mTitle = itemView.findViewById(R.id.textview_id_in_your_xml_file); 
    } 
} 

然後在onBindViewHolder設置它們:

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

編輯

如果你必須使用默認LinearLayoutManager屬性使用此構造函數:

layoutManager = new LinearLayoutManager(getActivity()); 

取而代之的是:

layoutManager = new LinearLayoutManager(this.getActivity(), LinearLayoutManager.VERTICAL, false); 

添加RecyclerView也是固定的大小屬性:

recyclerView.setHasFixedSize = true; 
+0

我還不,因爲我無法設置c要顯示的項目。我的子項目佈局有一些顏色,所以我知道它是否顯示。目前沒有設置任何東西,但這不是重點,如果是的話,它仍然不會顯示 –

+0

那麼任何建議? –

+0

@ user3806331發佈完成的單元格 –

2

變化:

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

android:layout_width="50dp" // set yourself 
android:layout_height="50dp" // set yourself 
相關問題