I have a ListView, in every element of that there is a TextView.
I'm looking for a way to update every TextView in the list every time the user's position changes. I have already implemented the permissionRequest for the Localization Services but I really don't know how to be informed every time the position changes.
I don't share code because I have only a lot of failed attempts.
What is in your opinion the best way to implement this kind of feature?
Related
I'm wondering how it can be handled.
I have a paginated list that needs to be refreshed pretty frequently. If I go to details of an item, and then back, I'd like to have current data but not lose everything I fetched previously (for example, if I fetched 3 pages I don't want to refresh only the first one). I think that is a common case, but I'm not sure how other people solve it.
My propositions:
Always refresh no matter what and ignore scroll position.
Request changes that happened between the last update and the current time from the backend.
Don't refresh anything, just inform the user that the list may not be up to date, and give the user button for refreshing if they want.
Send push from the backend every time something changes and handle it in the app.
What I suggest for your problem is either of the 2 solutions -
Refresh the screen but before refreshing take a note of the scroll item user was viewing previously, and then refresh the list and scroll to the item if found in the list else just scroll to the top and show a message "List has been refreshed".
Request changes that happened between the last update and the current time from the backend and then update the list accordingly same as the first solution.
The second approach is much improved and optimised if your backend permits that.
Happy to help,
Thanks & Happy Coding
I am using ListView which gets populated by the use of Adapter.
One of its features is also highlighting position on the list for the user with listView.getChildAt(savedViewPosition).setSelected(true).
At the conformation change, I would like to retaing poisiton of the selected item.
However, while I have tried several options, the best so far was to set a delay with .postDelay() and wait for the listView to load.
With this in mind, I would ask if there is any call that would enable me to wait until the items are loaded/visible and then posting the method immediately?
This sounds like something that could be accomplished by overriding notifyDataSetChanged() and selecting the item once the data has been loaded. There may be more to it to fit the exact behavior you want but it should be workable.
See the documentation here.
I need to implement the next logic in Android:
We have RecyclerView with hours of days (8.00-17.00, after 17.00 we see 8.00 of the next day, so the list is infinite) and should add events according to their time. I implemented it using LinearLayoutManager and view holder is a day where I add events to absolute position of view). But I don't like this way, because every item view is a bit havy and list doesn't scroll smoothly when draws new item. Please help me find correct way to implement it.
If the scrolling is not smooth then probably your onBindViewHolder is too heavy. There is no generic advice in this situation. You need to run Android Studio->Android Monitor->CPU->Start Method Tracing and analyse what actually slows down creating day view. Then optimise that part.
Also carefully check if you are not running any disk or database access code in UI thread. Move it to a separate thread.
I would like to start by saying if you can think of a better title for this problem, feel free to change it since I have no clue how to explain this in a short way.
So here is my problem:
For the application I am trying to make I have these schedules, one schedule for today, and one for upcoming days. Both of these are a listview inside a fragment.
(I used those fragments to create tabs to seperate the two.)
Each game (let's call them games because calling them activities would be confusing) on the schedule has a status, and here is where the annoying part comes. I have been asked to check if any game has been started, and if so I need to disable the buttons to start any other game than the one that is already ongoing.
EDIT: The main problem is that I cannot use findViewById on the listview item because apparently it is a null object reference
I made a little "paint"ing to give you more of a graphical representation.
So long story short, I need a way to check the status inside of every listview item inside of the listview inside of the fragment inside the activity to use said status to disable every button except for the one of the ongoing game.
Little side note: If no games have been started yet, all buttons are enabled.
I hope this made sense.
If you want some code to go with this, feel free to ask but be warned, I am making this inside a testing app so a lot of useless testing data and sloppy code.
EDIT:
This is where I am stuck in a more clear example:
The start buttons are enabled but should be disabled.
Scrolling further down the list, there is a started 'game' and right below it, a game with the same status as in the previous picture where the button is disabled as it should be.
This is because the "isStartable" boolean in my code goes to false after the game with status "start" has passed and the following items are disabled.
When I scroll back up, it is how it should be, the items are all disabled but I need them to be like this when the listview gets filled. Any way to refresh the data in this listview and taking the "isStartable" boolean with it?
This is what it looks like after I scroll back up.
create a model class for your listview data items. Set a boolean variable in model class like isGameStarted. Set that variable as per your result.Then in your listview adapter, put a condition as below
if(isGameStarted){
holder.startButton.setEnable(true);
else
holder.startButton.setEnable(false);
In my application, i have a ListView with a Custom adapter containing data like an image, 3-5 TextViews.
This data is fetched from a web server, until now i am showing something
This item is posted on Oct 10th 2012
but i want to change it to something like
This item is posted 6 days ago
So, its something like refreshing the ListView every 1 min, I dont want to use adapter.NotifyDataSetChanged() or something like that, which reCreates the whole ListView with the new data.
I just want that TextView alone to change in background and get displayed on the UI.
Thank You
One option would be to create a custom text view by extending the android TextView class and put a time task in it which update the text view message every one minute.
you can also use the
http://developer.android.com/reference/android/widget/TextView.html#onVisibilityChanged(android.view.View, int) to start and stop the timer task.
I don't think that is supported out of the box.
Since it seems you already have a Date/Calendar at hand just convert it to relative time string with a function like this: http://www.zachstronaut.com/posts/2009/01/20/php-relative-date-time-string.html
If you want real-time updates, I think your best bet is to start a background thread giving it the ListView and update the visible items periodically, however you may want to update all of them to prevent inconsistencies.
For Reference i suggest you to use below thing for change in ListView.
1.You need to get Row View for Particular item in which you want to change Textview.
2.Now from step 1 i believe you have your row view so apply change in it's child .