I have used listview.getCount()
how can I get count in case of Recyclerview
id = receiver + "-" + splashList.getCount();
Customized method in adapter:
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);
}
}
and calling of the method in another class:
CustomListAdapter1 mAdapter ;
mAdapter = new CustomListAdapter1(NewUI.this, dummy,
imgpath, bitmap, id, dateList);
mAdapter.setImage(myimage, rimage);
Simple answer: You should use RecyclerView in a situation where you want to show a lot of items, and the number of them is dynamic. ListView should only be used when the number of items is always the same and is limited to the screen size.
In this step, we will create a new layout file for the single list item view. Go to app > res > layout > right-click > New > Layout Resource File and name it as list_item. list_item. xml contains an ImageView and a TextView which is used for populating the RecyclerView.
A ViewHolder describes an item view and metadata about its place within the RecyclerView. RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive View. findViewById(int) results.
setHasFixedSize(true) means the RecyclerView has children (items) that has fixed width and height. This allows the RecyclerView to optimize better by figuring out the exact height and width of the entire list based on the your adapter.
there is no equivalent. The RecyclerView
has no direct knowledge of the underlying dataset. The closest thing is
int count = 0;
if (recyclerViewInstance.getAdapter() != null) {
count = recyclerViewInstance.getAdapter().getItemCount();
}
or if you have a reference to your adapter, simply call
int count = 0;
if (mAdapter != null) {
count = mAdapter.getItemCount();
}
//use this method to return recycler adapter item count..
private int recyclerCount(){
int Count = 0;
if (mAdapter != null) {
count = mAdapter.getItemCount();
}
return count;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With