l'm new here so hope to follow guidelines as I'm a newbie for both the side and android.
For my first app I'm trying to make a world clock.
In order to check it the time is shown and update in seconds. (00:00:00)
As the only thing I want to update every second is the time I don't want to use:
ListView's notfiyDataHasChanged()
I have a custom ListView & extended BaseAdapter and row.xml with each ListView item layout.
Trying:
lv.getChildCount() returns 0;
So I understand it has no child.
But I don't know how I can retrieve the View of the specific item in the listview.
Then call that view's TextView by findViewById(R.id.time) and set it each second.
I've googled and read alot of threads but still didn't get that :(
Thank You.
I would go a different way about that problem: Subclass the TextView widget into your own TimeView widget and include that one in your row layout.
The TimeView widget will own a handle that calls itself to refresh the view.
Hence, automatically, all views visible in the list will update themselves, the other adapter items will not be having views and won't as a consequence require any update.
Related
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.
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.
I am developing an activity with a ListView in which I need to change the current row by another layout by clicking on the row, and I'm not finding any way to do as much as I look (I take hours searching for possible solutions and I have not seen any reference to this problem). I do not know if this can be done in Android, but if anyone has an idea of how to do this would be appreciated.
Thanks in advance.
PS: The ListView control is normal and just want to replace a layout with a different layout. I'm using the API 15.
Use a ViewSwitcher
http://developer.android.com/reference/android/widget/ViewSwitcher.html
A ViewSwitcher is -
ViewAnimator that switches between two views, and has a factory from
which these views are created. You can either use the factory to
create the views, or add them yourself. A ViewSwitcher can only have
two child views, of which only one is shown at a time.
I suggest merging the two layouts in a single one and hide the second one. In your adapter data you should have a flag or something to indicate which layout to display. When you click a row, toggle that flag for the selected item and notifyDataSetChanged() on the adapter. This will make sure the changed layout remains even if you scroll up and down and the row goes off screen.
A more optimized solution is to have different item types in the adapter.
I know that similar questions have already been asked but I do not understand what would be the correct approach of solving the issue, yet.
I would like to change the background color of a ListView row when the user clicks it. However due to Android reusing the row layouts when scrolling, the background color gets repeated for other rows. I am wondering what would be the correct approach of maintaining the original layout for all rows except the one changed programmaticaly and also maintain the changed layout information for that row for scrolling back. I am using a SimpleAdapter which is passed the rows layout's XML.
Regards
Your rows' capabilities within your ListView largely depend on the kind of Adapter you are using. In any Adapter where you manually construct or inflate the View per item, you can change the layout properties per item, as long as you do so within the Adapter. Simply add your background color code to when the item's View is built, and it will work like a charm. If you are not able to do so with the current Adapter, consider extending the current one or using a different adapter.
Note: I haven't placed code directly within this answer because where you add it depends upon your own implementation. For instance, I would add .setBackgroundDrawable() to bindView() in an extended CursorAdapter.
Hope this helps,
FuzzicalLogic
I have a simple problem:
i have a listview with 2 TextViews one shows a number and the other shows the diff from last time the number has chnaged.
What im trying to do is every time the getView is called on my adapter show an animation on the second TextView based on the change in the first Textview number. im trying to do this for all of the items inside the listview and it doesnt work.
What is the best way to achieve this?
Thanks,
Totem
The simplest way you can achieve this is by extending SimpleCursorAdaptor or ArrayAdaptor (How to...)
in the bindView method you based on the logical check you can then show the animated version of the TextView and hide the none animated.
This is the easiest way I have implemented.
http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/