Updating android listView adapter's items' view - android

I'd like to change my listView items dynamically. The algorithm goes like this:
1.I create the default view for my listView using adapter and show it to user. The list item contains Imageview, textview and another imageview which is invisible.
2.The data is beeing dowloaded in the meantime.
3. after my data is downloaded, I'd like to check whether my listview contains any of downloaded items. If yes, I want to make visible the previously invisible ImageView for this item.
Should I add some kind of method to my adapter, call it and then call invalidateViews(), notifyDataSetChanged(), or notifyDataSetInvalidated()? Or maybe there is some kind of standard way to find my adapter's item by Id or sth and then make visible the imageview for this item?
This list update operation is the only one left to implement for me.

Should I add some kind of method to my adapter, call it and then call invalidateViews(), notifyDataSetChanged(), or notifyDataSetInvalidated()?
Yes, exactly.
maybe there is some kind of standard way to find my adapter's item by Id or sth and then make visible the imageview for this item?
Above mentioned way is enough. There is no such standard or special way to do it AFAIK.

Read the Displaying Bitmaps Efficiently introduction and in particular the part about Handle Concurrency. This will give you all the information you need.

Related

Access Adapter items of Recyclerview

I'm using Recyclerview to show a list. I want to delete some items like IOS. In my listview template I have added a button to delete item which is invisible by default. In my activity I have another button attached at bottom (Not part of listview) and on tap of this button I want to make all delete buttons of listview visible.
My Question is how can I get reference to all delete buttons of listview in activity and is it the right way to do this?
Thanks
Assuming you have ViewHolders set up, you already have references to all the buttons in your list. All you have to do is to make them visible for every item in the list with a simple loop.
In case you haven't implemented ViewHolders I suggest you check out the documentation and take a look at some simple tutorials on how to use them.
On a side note. If I understood correctly you're making a bottom tab for your app and since you referenced iOS I gotta say this; Remember that Android and iOS are two unique operating systems with their own ways of handling things. Check out Googles pure Android documentation.
In your question title you say RecyclerView, but in your text you say ListView. The solution is similar either way, but it's best to be perfectly clear what you're doing.
In either case, there are at least two different solutions.
First, you could use a boolean flag to determine if all the the item buttons should be showing or not. You check this flag at the time the item view is inflated or created and toggle the button accordingly. If the boolean flag is ever changed, the easiest thing to do is tell the RecyclerView/ListView that the underlying data has changed and to redraw all the views. Call notifyDatasetChanged on the adapter.
The other thing you can do at the time the item buttons should change is iterate all the visible item views, find the button, and change its visibility. With RecyclerView, you can do this, and with ListView you can do this.

How to update a single view of listview instead of notifyDataSetChanged in android

I want to update single row of listview which contains a image after certain time of addition to listview. I am using notifyDataSetChanged for this but when other visible views contains a imageView, it gets a jerk felling on other visible imageViews due to notifyDataSetChanged.
Can someone suggest a better way to do it.
Thanks
Keep a reference to the imageview when you create/update it in the adapter. You can then change the image later on. However, since list items get recycled, you will want to set a tag on it with some id of the content so that you make sure you're still updating the right item.

Footer as a one of the item on the ListView.

I'm trying to achieve the effect of the footer for ListView but without using the addFooterView method of the ListView. My intention is to treat the last visible item of the list as a pinned footer. In my view I can achieve this by detecting the last visible item on the list and dynamically change it's layout. I did some research and I think I must extend the BaseAdapter class providing two types of items. One for ordinary item on the list indicating that adapter should inflate the item with ordinary layout. And the second one indicating that adapter should inflate the current item with layout of footer. I think i must override the onScroll method to detect the last visible item. And here are my questions. Should i call the getView method from the onScrollmethod ? Is it the proper way to implement such effect? Is it possible at all? I would be grateful for any suggestions.
Thank in advance.
And here are my questions.
Should i call the getView method from the onScrollmethod ?
no, you should never directly call getView(). Only classes that extend AbsListView call getView
Is it the proper way to implement such effect?
No. The proper way of doing it is calling addFooterView to your ListView object.
Is it possible at all? I would be grateful for any suggestions.
No, it's not possible. Using scroll listeners you will never be able to find out when the AbsListView is requesting the "last view". That's because ListView does not guarantee the order it queries for Views. That's specially true when you 1st set the adapter or call notifyDataSetChanged which causes the ListView to get the views in several points to be able to layout and measure stuff it needs.
The suggestion is to use the addFooterView method, that's the correct way of doing, that's why it's there.

Individual preference for each listview item example

What's the easiest way to create separate preferences for each item in an Android listview? I found this question, but it's kind of general. Could anyone be more specific, possibly show a quick example?
If you want to do this, you should write some code into your adapter getView method.
You can check the position (with an if-clause) in the method and add a custom desgin/layout depending on the position.
If you use a LinearLayout or RelativeLayout in your ListView item XML you can fill this programmatically in the getView method with all the widgets (edittext, checkbox, etc) you need.

displaying item on specific listview item only

I am trying to get a button to show up on my list item (declared as android:visibility:"gone" in the XML) to show as visible when I perform some gestures on it. However, how can I actually notify the getView method correctly to display the button only on the listview item?
I tried using getChildAt(position) which ended up displaying several buttons at once.
I tried passing in the position for example I detected that the gesture was performed on from pointToPosition and passed it into the adapter for the getView method to display, but it had the same problem of displaying several at once.
do anyone know how can I solve this?
I think you may have a misunderstanding of how Adapter.getView() works its meant to create or reuse layouts when rendering the ListView it also needs to be fast so conditional manipulation in this method is discouraged. Although ListView.getChildAt() may work it does not effectively use the API. Your adapter will have a setViewBinder() unless you're using an ArrayAdapter (if so I suggest using SimpleAdapter because of the additional features). Use your ViewBinder implementation to switch the visibility of the button.
If you'd prefer to continue to use ArrayAdapter use ListView.getChildAt(int) to findViewById(R.id.your_button).setVisibility(). If this is what you already tried and its setting all the buttons visible then please post the related code.

Categories

Resources