在Recyclerview的情况下,listview.getCount的等价物是什么

时间:2015-07-04 07:18:57

标签: android android-recyclerview

我已使用listview.getCount()如果Recyclerview

,我该如何计算?
id = receiver + "-" + splashList.getCount();

适配器中的自定义方法:

public void setImage(String my_image, String r_image) {
    byte[] decodedrimage = Base64.decode(r_image, Base64.DEFAULT);
    Bitmap decodedrByte = BitmapFactory.decodeByteArray(decodedrimage, 0,
            decodedrimage.length);
    if (my_image.equals("empty")) {
        imgflag = 1;
    } else {
        byte[] decodedmyimage = Base64.decode(my_image, Base64.DEFAULT);
        Bitmap decodedmyByte = BitmapFactory.decodeByteArray(
                decodedmyimage, 0, decodedmyimage.length);
        rimage = createCirclebitmap(decodedrByte);
        myimage = createCirclebitmap(decodedmyByte);
    }

}

并在另一个类中调用该方法:

CustomListAdapter1 mAdapter ;
mAdapter = new CustomListAdapter1(NewUI.this, dummy,
                imgpath, bitmap, id, dateList);
mAdapter.setImage(myimage, rimage);

2 个答案:

答案 0 :(得分:23)

没有等价物。 RecyclerView没有直接了解底层数据集。最接近的是

int count = 0;
if (recyclerViewInstance.getAdapter() != null) {
     count = recyclerViewInstance.getAdapter().getItemCount();
}

或者如果您有对适配器的引用,只需调用

即可
  int count = 0;
  if (mAdapter != null) {
     count = mAdapter.getItemCount();
  }

答案 1 :(得分:1)

//use this method to return recycler adapter item count..
private int recyclerCount(){
 int Count = 0;
  if (mAdapter != null) {
     count = mAdapter.getItemCount();
  }
return count;
}