How to create textview that hold the count of items in recyclerview in android studio
You can get position of first visible item in your recyclerview from findFirstVisibleItemPosition() method of the recyclerviews' Layout Manager
mRecycleView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int positionView = ((LinearLayoutManager)recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
textView.setText(Integer.toString(positionView)); //The TextView you want to update
}
});
Not getting total item count from recyclerview
I also tried this but failed so I instead used snapshot.getchilderncount
In my firebase database reference and checked if childrencount =0 or not
Create a value event listener
For your apointment database reference and in it say if(snapshot.getChildrenCount==0) { ///your logic }
How to sum cardView item values in recyclerView and display the total sum on a textView outside the recyclerView
it works like this for me, I changed notifyDataSetChanged(); into notifyItemChanged(position);
so that I can get the total value (v4) and pass it to text view as shown
@Override
public void onClick(View view) {
int position = getAdapterPosition();
Element element = this.element.get(position);
String bd= element.getCode();
List<Price> priceList = priceDao.queryBuilder().where(PriceDao.Properties.ElCode.eq(bd)).list();
String pricev = priceList.get(0).getPriceValue();
// Calculating the total price of each
v6 = Float.parseFloat(pricev);
x3=v6*count;
v5=0;
count= Integer.parseInt(element.getCount());
if(view.getId()==add.getId()) {
count = count+1;
c = String.valueOf(count);
element.setCount(c);
elementDao.update(element);
notifyDataSetChanged();
v5=1;
} else if (view.getId()==sub.getId()) {
if(count==0) {
count = 0;
c = String.valueOf(count);
element.setCount(c);
elementDao.update(element);
notifyDataSetChanged();
v5=3;
}
else {
count = count-1;
c = String.valueOf(count);
element.setCount(c);
elementDao.update(element);
notifyDataSetChanged();
v5=2;
}
}
count= Integer.parseInt(element.getCount());
}
}
///////////////////////////////
so that I can get the total value (v4) and pass it to text view as shown
@Override
public void onBindViewHolder(final MyListsToOrderAdapter.MyHOldd holder, final int position) {
priceDao=setUpDBPrice();
String bs= element.get(position).getCode();
List<Price> priceList = priceDao.queryBuilder().where(PriceDao.Properties.ElCode.eq(bs)).list();
String pricev = priceList.get(0).getPriceValue();
// Calculating the total price of each
v1 = Float.parseFloat(pricev);
v2= Float.parseFloat(element.get(position).getCount());
v3=v1*v2;
final String res = String.valueOf(v3);
holder.listName.setText(element.get(position).getDescription());
holder.add.setImageResource(R.drawable.add);
holder.sub.setImageResource(R.drawable.minus);
holder.pricess.setText(pricev);
holder.totalPriceT.setText(res);
holder.status.setText(element.get(position).getCount());
holder.addNote.setText("Add");
// Calculating the Total price of all items
if(v5==1)v5=v6;
else if(v5==3) v5=-v6;
else if(v5==2) v5=0;
else v5=v3;
v4=v4+v5;
// displayin on the textView
String ch = String.valueOf(v4);
textView.setText("Total: "+ch);
}
Related Topics
How to Fix Mass Assignment: Insecure Binder Configuration (Api Abuse, Structural) in Java
Java.Io.Filenotfoundexception: (Access Is Denied)
How to Return a Zip File to the Browser Via the Response Outputstream
How to Move Marker Along Polyline Using Google Map
Eclipse Problems View Not Showing Errors Anymore
How to Test a Void Method Using Junit And/Or Mockito
How to Replace Non-Printable Unicode Characters in Java
Launch New Activity from Fragment in Android Studio
Largest and Smallest Integer - Exercise from Deitel'S Java Book
Httpclienterrorexception 400 Null Using Resttemplate in Microservices
Convert Yyyy-Mm-Dd Hh:Mm:Ss.Sss Zzz Format Strin to Date Object
Spring Security - 405 Request Method 'Post' Not Supported
How to Return Different Types of Responseentity in Spring MVC or Spring-Boot