2016-05-30 6 views
-2

私のリサイクラビューは空ですが、左右にスクロールすることができます(画面の端にあるインジケータがわかります)が、個々のリストアイテムは表示されません。ここでRecyclerView Empty

が主な活動のための私のコード

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_split_order); 
    android.support.v7.app.ActionBar mActionBar = getSupportActionBar(); 
    mActionBar.setDisplayHomeAsUpEnabled(true); 

    setTitle("Split Order"); 

    //Code to get Screen Width and Height 
    DisplayMetrics displaymetrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
    int height     = displaymetrics.heightPixels; 
    int width     = displaymetrics.widthPixels; 
    int onequaterscreen   = width/4; 
    int onefifthheight   = height/ 5; 


    recList = (RecyclerView) findViewById(R.id.rv_bill_list); 
    recList.setHasFixedSize(true); 
    createData(); 
    adapter = new BillListAdapter(this,data); 
    LinearLayoutManager llm = new LinearLayoutManager(this); 
    llm.setOrientation(LinearLayoutManager.HORIZONTAL); 
    recList.setLayoutManager(llm); 
    recList.setAdapter(adapter); 

} 

public void createData(){ 

    data = new ArrayList<>(); 
    BillItem dummy = new BillItem(); 
    dummy.setDiscountAmt(0.0); 
    dummy.setOrderNum(44); 
    dummy.setSubtotal(0.0); 
    data.add(dummy); 
} 

アダプタ

private LayoutInflater inflator; 
List<BillItem> billItemList = Collections.emptyList(); 

public BillListAdapter(Context context,List<BillItem> billItemList) { 

    inflator = LayoutInflater.from(context); 
    this.billItemList = billItemList; 

} 

@Override 
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

    View view = inflator.inflate(R.layout.bill_list_item,parent,false); 
    MyViewHolder holder = new MyViewHolder(view); 
    return holder; 
} 

@Override 
public void onBindViewHolder(MyViewHolder holder, int position) { 

    BillItem current = billItemList.get(position); 
    holder.tv_bill_subtotal.setText(String.valueOf(current.subtotal)); 
    holder.tv_bill_discount_amt.setText(String.valueOf(current.discountAmt)); 
    holder.tv_bill_num.setText(String.valueOf(current.orderNum)); 

} 

@Override 
public int getItemCount() { 
    return 0; 
} 
class MyViewHolder extends RecyclerView.ViewHolder{ 

    TextView tv_bill_subtotal; 
    TextView tv_bill_discount_amt; 
    TextView tv_bill_num; 
    RelativeLayout rl_bill_discount; 
    ListView lv_orderItemList; 

    public MyViewHolder(View itemView) { 
     super(itemView); 
     tv_bill_num   = (TextView)  itemView.findViewById(R.id.tv_bill_num); 
     tv_bill_subtotal  = (TextView)  itemView.findViewById(R.id.tv_bill_subtotal); 
     rl_bill_discount  = (RelativeLayout) itemView.findViewById(R.id.rl_bill_discount); 
     lv_orderItemList  = (ListView)  itemView.findViewById(R.id.lv_orderitemlist); 
     tv_bill_discount_amt = (TextView)  itemView.findViewById(R.id.tv_bill_discount_amt); 
    } 
} 

レイアウトファイルである私が値を確認するために、デバッガを使用

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

<RelativeLayout 
    android:id="@+id/rl_bill_sidemenu" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentStart="false" 
    android:layout_alignParentLeft="false" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:background="@color/colorWhiteBrighter"> 

    <TextView 
     android:paddingLeft="@dimen/sidemenu_horizontal_margin" 
     android:paddingRight="@dimen/sidemenu_horizontal_margin" 
     android:paddingTop="@dimen/sidemenu_vertical_margin" 
     android:id="@+id/tv_bill_num" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/ordermenunum" 
     android:textSize="20sp" 
     /> 


    <!-- 
    Order List Header 
    --> 
    <RelativeLayout 
     android:id="@+id/rl_billitemlistheader" 
     android:orientation="horizontal" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:paddingLeft="@dimen/sidemenu_horizontal_margin" 
     android:paddingRight="@dimen/sidemenu_horizontal_margin" 
     android:layout_marginTop="@dimen/sidemenu_vertical_margin" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tv_bill_num" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:background="@color/colorWhiteHighlight"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/ordermenuqty" 
      android:textSize="14sp"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="40dp" 
      android:text="@string/ordermenuname" 
      android:textSize="14sp"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="@string/ordermenuprice" 
      android:textSize="14sp"/> 


    </RelativeLayout> 

    <ListView 
     android:layout_below="@id/rl_billitemlistheader" 
     android:id="@+id/lv_orderitemlist" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/rl_subtotal"> 

    </ListView> 




    <!-- 
    Pay Button 
    --> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:padding="@dimen/sidemenu_vertical_margin" 
     android:background="@drawable/greenbutton_selector" 
     android:id="@+id/rl_bill_pay" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <TextView 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="28sp" 
      android:textColor="@color/colorPrimaryDark" 
      android:text=">>"/> 

     <TextView 

      android:id="@+id/tv_total" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="28sp" 
      android:textColor="@color/colorWhiteBrighter" 
      android:text="@string/zerodollars" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 


    </RelativeLayout> 

    <!-- 
    Subtotal Field 
    --> 
    <RelativeLayout 
     android:id="@+id/rl_subtotal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:paddingTop="12dp" 
     android:paddingBottom="12dp" 
     android:paddingLeft="@dimen/sidemenu_horizontal_margin" 
     android:paddingRight="@dimen/sidemenu_horizontal_margin" 
     android:background="@drawable/submenu_selector" 
     android:layout_above="@+id/rl_bill_discount"> 

     <TextView 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14sp" 
      android:text="Subtotal:"/> 

     <TextView 
      android:id="@+id/tv_bill_subtotal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14sp" 
      android:text="@string/zerodollars" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 
    </RelativeLayout> 
    <View android:layout_width="fill_parent" 
     android:layout_height="1dp" 
     android:background="@color/colorWhiteDarker" 
     android:layout_below="@+id/rl_subtotal" 
     /> 

    <!-- 
     Discount Field 
    --> 
    <RelativeLayout 
     android:id="@+id/rl_bill_discount" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:paddingTop="12dp" 
     android:paddingBottom="12dp" 
     android:paddingLeft="@dimen/sidemenu_horizontal_margin" 
     android:paddingRight="@dimen/sidemenu_horizontal_margin" 
     android:background="@drawable/submenu_selector" 
     android:layout_above="@+id/rl_bill_pay"> 

     <TextView 

      android:id="@+id/tv_discount_lbl" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14sp" 
      android:text="Discount($):"/> 

     <TextView 
      android:id="@+id/tv_bill_discount_amt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14sp" 
      android:text="@string/zerodollars" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 

    </RelativeLayout> 
    <View android:layout_width="fill_parent" 
     android:layout_height="1dp" 
     android:background="@color/colorWhiteDarker" 
     android:layout_below="@+id/rl_subtotal" 
     /> 


</RelativeLayout> 

あり、何もないヌル。私はリストアイテムがないと思うのビューを膨らませていません。

答えて

1

getItemCount方法は

+0

のようなアダプタのgetItemCount()をオーバーライドする必要があります0

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

戻りますが、アダプタクラスに渡すのArrayListのサイズを返しますそのような小さな間違いが働いてくれてありがとう。 –

+0

10分しかマークできないので、覚えておいてください!再度、感謝します。 –

+0

確かに、私はあなたを助けることができてうれしい –

0

あなたはこの

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