How to get a callback when item inside RecyclerView is hidden/visible? - java

I have a RecyclerView with a GridLayoutManager with video streams in each grid cell. I need some kind of callback for visibility on each cell to know when to stop the video in the cells that are not visible on screen and start the videos on the cells that are visible.
I've experimented with RecyclerView.OnScrollListener to then use findFirstCompletelyVisibleItemPosition and findLastCompletelyVisibleItemPosition to get the range of visible items. But I haven't found a way to find the items that have moved out of screen.
Is there a way to obtain all the hidden and visible items from the RecyclerView or RecyclerView.Adapter or GridLayoutManager? Or is there a way for the RecyclerView.ViewHolder to listen for changes in its hidden/visible state to stop the video?

Related

ProgressBar in Recyclerview with Java

For Home fragment, I use a ProgressBar in in RecyclerView.Adapter. When the App starts everything render without problem. But when I come back from the other fragment with this code:
Navigation.findNavController(view).navigate(R.id.action_nav_dashboard_to_boxFragment);
Then the ProgressBar will be rendered for all recycler items with the same state
holder.progressBar.setProgress(percent, true);
RecyclerView uses one view multiple times, when it contains the list which is not displaying on the screen at a time(means a list contain large amount of items which is not displaying on screen at same time you need to scroll up and down). When user scroll the list the offscreen items are reused to display the remaining list items which is called recycling.
To Stop recycling the items call this method in your onBindViewHolder method:
holder.setIsRecyclable(false);

How can I make checkboxes visible for all recycler view items without calling notifydatasetchanged?

I have been trying to make a photo gallery app and I want to select multiple photos.
The problem in the current implementation is that when I try to longpress to make checkbox visible, the thumbnails are reloading for a fraction of second.
This is because I am calling notifydatasetchanged() after I longpress so that onbindviewholder can load the checkboxes on the screen for every recycler view item, which in turn reloads the thumbnails.
I am using glide to load thumbnails.

Android Studio: ListView OnClick animation doesn't work if you set background color of items

In my project I've setted the background color of my items (composed of several elements inserted in a ConstraintLayout) inside a ListView but the default animation of click and long click disappears if the background color is not at least a little transparent. In fact, as transparency decreases, the effect of clicking on the elements is less and less evident. In a few words, color goes to hide the animation if isn't transparent. How to solve this problem and then bring selection animation to the foreground?
Same problem, still unresolved: ListView items not showing tap animation
RESOLVED!
You have to simply add android:drawSelectorOnTop="true" in your ListView XML tag. In this way you can modify and customize the list item background and at the same time bring back the "selector" on top of the "z axis" of GUI. Yuhu!
If you are giving a background coloraturas to the list items then you might be hiding the system press animations. in this case you can use the methods like OnItemLongClickListener() and itemClickListener () and add your custom animations to the view.

changing listview item elements

I'm new to Android development.
I need to make a listview with text and icon audio player. The icon has three States, "download", "downloading", "play" and "pause". The idea is that when populating the listview, set the "download" icon if the track is not downloaded and "play" if the track is downloaded". If a person clicks the "download" button the icon should be updated to "downloading" to start the download, then when complete, you should see the icon "play". If the user presses the "play" icon for this element should be updated to "pause".
I can't change the icon . I tried to change them in onItemClickListener and make the onClick in the getView method in adapter, but when scrolling the icons changed to the old. And if you select multiple items in the list, then change all the icons, and I need to change only one, for playing of the track.
I didn't show the code because there is nothing that can be corrected. - all wrong
if you have your own adapter try using a method notifyDataSetChanged();
That is happening due to recycling of views. If you click on an item and you will see multiple items clicked.
Use RecyclerView instead of listView, which will handle recycling by its own and its ViewHolder class takes care of the issue you are having.
And don't forget to notify the recyclerView adapter whenever you make some change in data source (i.e. arraylist)
Check out this example...
Hope it helps
http://hmkcode.com/android-simple-recyclerview-widget-example/

ImageView Onclick Animation

Below is a picture of my app, I am currently using a modified version of this app to show my expandable content. Now my problem is with my ImageView, I currently have 3 layouts, one for the main dialog (with listview), one for the listview title & arrow and one for the item details (item row once expanded). I want to add animation to the ImageView so when you click the image or title textview, the list will expand and animate the change. How can I do this? I cannot get the onClick to work because it doesn't know there are 2 imageviews, it seens only one...
I will assume that your ImageView is this arrow inside your ListView element (because you didn't write it clearly enough).
You probably shouldnt try to attach onClickListener to your ImageView at all (nor to your ListView element title). The good way of implementing what you want you achieve would be to use ListView's onItemClickListener to detect clicks performed on specific items inside your listview, and then expanding appropriate expandable content.

Categories

Resources