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.
Related
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 need to make an application that will basically be a 5 "page" quiz with true and false buttons. I don't think that a new layout/activity is needed for each "page". That would be overkill. Would a fragment or ViewPager be appropriate? Does it break any Android Guidelines? They both seem to make sense to me. Maybe fragments a little more because of a tablet/alternate layout. Any ideas would be appreciated.
I've been using the ViewPager in one of my projects, for side swiping between similar yet distinctly different views.
It is working very well.
It depends on your flow. View Pager will work well if your users can randomly go through the views. If you want things to be in a specific order then ViewPager probably won't work.
you can achieved by creating 5 pages dynamically and load that in single layout/activity
By using dynamically load pages helps In future you want to add 2 pages of question its easy to do
According to your flow u can use the this also In same activity you can change the question just on click of button.
And if you want user to revisit all question u can use view pager.
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.
I'm not looking for exact code here, just a direction on what to look for and what I should be reading about so I can figure this out.
I have a layout that I would like to remain static, with only the listview changing depending on what's selected from the list. I've reloaded data in the list, but I would like the fancy transition animations between choices, and would like the app to go to the previous menu when pressing back.
Someone suggested using a viewswitcher, which seems like it'd be great, but I am still unsure about how to fill a listview in a layout with a regular row layout, then on selection do an animated transition to a custom row. Also, it seems the viewswitcher is limited to two views, so it may be a limitation when I want to go a few menus deeper.
Preferably, I'd like to put each menu in it's own class so that I can handle filling it in that class, if possible...
Hope this isn't too vague, but if it is I'll be more than happy to explain myself further.
Don't know if it's what you meant but have you tried showing and hiding the views?
findViewById(R.id.listViewID).setVisibility(LinearLayout.GONE); //hide the one you want
findViewById(R.id.listViewID2).setVisibility(LinearLayout.VISIBLE); //show the one you want
Hope it's what you meant :)