Is there a way to create an onChildAdded or onItemAdded listener to a GridView in android? I can't seem to find one online. Right now my approach is lacking, I feel that it should be improved. I have a worker thread running that remembers the number of children that the GridView has, then if it has more it calls a method that handles the event and if there are less then it calls another method. I'm sure there has to be a better way, but I don't know of one.
Any suggestions are welcome.
You should write your own Adapter, extending BaseAdapter. Check this out.
Related
I am using a RecyclerView to display data that gets polled from a website (=> completely changes at once).
I already created an ItemAnimator class that has the animation I want but I need to know what is the best way to time the animations to wait for the previous one to finish.
This is what I'm trying to achieve: http://www.google.com/design/spec/animation/meaningful-transitions.html#meaningful-transitions-hierarchical-timing
We've had a lot of success using setStartDelay (or setStartOffset, depending on which animators you are using). Have a delay variable that starts at 0, and as you walk through your children creating their animations, set the start delay to the current value and add some increment, such as 100 ms.
I've been working on the exact same animation. I've put it to the side for the time being, but got a pretty good effect at normal speed. When I slowed it down for debugging, I've got a strange bug that causes certain items to be animated multiple times. Also, scrolling up doesn't quite work if the animation hasn't completed, but that isn't a bug likely to be run into at normal speed.
Here's my code: https://github.com/halfjew22/AnimateRecyclerGrid
Essentially, what I did was I looked at the pattern in the Material Animation. Based off of that pattern, I put together a for loop that spawns a runnable that is given coordinates (based off the value in the for loop) and told to animate the view with those coordinates.
Like I said, I didn't quite finish the project, but it works fairly well as an alpha or proof of concept. I know it's been a while since you asked this question, but let me know if you'd like to work on finishing this up together.
Let me know if that helps you out.
I've created a custom RecyclerView adapter class which does more or less what OP wanted to achieve i.e. animates RecyclerView's items sequentially (in order, one after the other).
The adapter class is shared publicly on github as a gist here.
From the description:
"This adapter aims to create a sequential RecyclerView items' animation.
They're appearing in order, top to bottom. The animation works when the RecyclerView is first created and does NOT work when items are scrolled down."
I need some help.
I'm wanting to make an activity similar to this, but I'm not sure where to start.
Basically, it's like a texting UI, with the users question on the right and the answer on the left. I was going to use a list view for the sake of simplicity, but I dont' think it'd support this kind of structure.
I googled some layouts where I can scroll, but most of them require me to premake them, which isnt an option because its a dynamic chat log.
Does anyone here have experience with this kind of UI? Can you point me in any direction? I hate to ask such a strange question, but I don't even know how I'd word this situation on Google.
Thanks in advance.
What you're looking for is a ListView where you can return a different layout depending on whether the message is sent or received. A ListView is the most efficient implementation for this because its ideal for displaying a potentially large data set without having to keep a view in memory for every row.
This is achieved by extending the BaseAdapter in your application and overriding the getItemViewType(), getViewTypeCount(), and getView() methods (along with all the other methods required by a ListView adapter).
This is a good tutorial that serves as a walkthrough for this pattern.
Instead of using ListView, You may programmatically construct a viertical LinearLayout, and add TextView in each line, you can set the alignment of the TextView in lines accordingly.
Sorry for my amatuer question, but I'm really new to Android, and even Java.
I have a listview layout in my appwidget. The listview items are handled in widgetservice.java, where i declared an array to store the listview items in.
There is a configuration button for every listview item. When you click on them a new activity starts, and i really need to acces the listview items in this activities (so actually an element of the before mentioned array).
I did some research how to do that, and I came accross with the Parcelalbe class, so that i can attach a Parcel to my Intents. That is great, however the parcels seem to be just mere copies, and i need my original array elements (so i can change them in the activities, etc).
I hope you could understand my problem, and would able to help me.
Cheers.
Parcelable is one way to go but unless you are just dealing with basic, single dimensional, String only Lists/Arrays than I wouldn't go down that route as it can get complicated quite quickly and is not hugely flexible.
The preferred way to go about this is using Fragments. Such as the ListFragment in this case.
Your ListFragment contains all the bits and pieces it needs to display a ListView. It should generate (or be able to access) it's own collection of items and know how to display and control them. The benefit of putting it all into a Fragment is that you can then easily reuse it in any Activity or layout.xml you like and make use of the same functionality again without having to duplicate all that code.
If you need your ListFragment to be dynamic and not just display the same list all the time you can pass it some parameters through a newinstance(...) method. That method will itself wrap all the info and arguments you want into a Bundle object that you will use to configure or populate your Fragment. Here's how to go about that.
What that ensures is that if your Fragment needs to be recreated (screen rotate, Activity change, Application focus etc etc) it will be able to recreate itself properly using the same parameters again without you having to intercede.
It may seem like more work now to try to get your head around the concept and use of Fragments but in the long run it will save you time, spare you headaches and let you write more maintainable and appealing code.
As a C# developer I'm trying to get familiar with Java and more specifically, the Android framework.
I've created some very basic intro Activities, but I'm now trying trying to get a ListView up and running with 'databinding'. I found this sample code: http://developer.android.com/guide/topics/ui/layout/listview.html
I don't think I've fully grasped the concept of these views yet, because initially I figured that the ListActivity class that I created would be built as some sort of a user-control that I could simply replace my ListView with. When I look at the code though, it appears as though it's somehow trying to hook into an existing view which confuses me. (How do I call this ListActivity from my current activity, and how do I use it with my ListView?).
getListView().setEmptyView(progressBar);
Could someone please clarify what's going on? Perhaps I've become too .NET paradigm orientated and I'm not understanding the picture properly.
A ListActivity is an activity that assumes that you will set a layout with a list view in it with a certain id. It will then store that view in a variable so getListVew() will return it. Basically its a tiny bit of syntactic sugar to do what you can do yourself with 3 lines of code.
Really I don't think its worth using. You can use listviews in a regular activity, it takes 1-3 lines of code to do everything the ListActivity does, and you don't have problems if you name your listview with a different id or if you even decide to not have a listview down the road.
I'm looking at some demo code that shows how to use a Fragment Adapter (Tab Adapter in this case). I'm curious as to what exactly the instantiate() method does. I see it used in the following demo code on this page:
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
(see the getItem() method within the TabsAdapter class)
If I'm reading the demo code correctly, every time a user clicks on one of the tabs, a new Fragment is created? And thus the fragment starts the entire life-cycle again (onAttach()...onCreate()... etc)? This sounds awfully inefficient. I would think that the fragment that will represent the content for each tab should be instantiated only once (perhaps in the addTab() method), and then saved into some collection where it can be fetched when getItem() is called.
Please correct me if I'm mistaken in any of this. I'm trying to better understand how to manage fragments.
My money would be on that the setCurrentItem() function doesn't actually destroy the existing Fragment being shown in that tab. Otherwise there's really not much of a reason for the adapter to have a List of available tabs. Likely, when you switch from one tab to another, setCurrentItem() just detaches the UI from the currently active Fragment (or calls its onPause() method) and then re-attaches the UI for the newly selected Fragment (or calls its onResume() method).
But, if you're in doubt, you could read the source :)
Hope it helps,
David
I was able to find an explanation for my question here