How do I set up non-scrolling lists? - android

I am trying to produce an activity with an interface somewhat like that of the 'add contact' activity in the standard people application - ie something with a number of lists (email addresses, phone numbers, etc) each of which has a variable number of entries and an 'add' button. The lists themselves don't scroll (ie all entries are shown all of the time), but the overall interface does scroll.
My first attempt uses several listviews inside a linearlayout inside a scrollview; the code adds elements to the listviews as required. However, I cannot find a way to prevent the lists from being scrolled, rather than being shown full length.
Can anyone suggest how I might stop the listviews from scrolling ? Or perhaps suggest a better container than the listview (I don't want to re-invent the wheel) ?
Thanks,
Richard

Have you considered using table view instead? It should be possible to make rows clickable. Here is how to create table rows in code in my other answer:
How to populate the TableLayout with ImageView dynamically in android jdk?

Maybe ExpandableListView will be more helpfull here. http://developer.android.com/reference/android/widget/ExpandableListView.html for more info

The lists themselves don't scroll (ie all entries are shown all of the time), but the overall interface does scroll.
This is incorrect. All entries are not shown all of the time.
My first attempt uses several listviews inside a linearlayout inside a scrollview
You cannot put a ListView in a ScrollView.
Or perhaps suggest a better container than the listview (I don't want to re-invent the wheel) ?
The add-a-contact activity uses a ScrollView wrapped around a LinearLayout holding each of the "editors".

Related

How to design expandable listview with different childs

This is how my screen should look like. The problem for me here is, I should pass User object to adapter and fill those fields with user object fields. How could I know which field to update if I create child layout with one TextView?
Is it a better idea to create for example DetailsViewHolder, AddressViewHolder, etc? Or I can create details.xml with 6 Edittexts? but I don't think that's a good idea, right?
ListView is best for long lists that may change with time. For your situation I wouldn't recommend using a ListView at all, but rather a simple LinearLayout. It is much easier to work with and gets the job done perfectly. If you need scrolling, just wrap the LinearLayout inside a ScollView.

Android ListView custom row overlay

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.

Efficiency of Listview with the flexibility of the ScrollView

I am trying to figure out the best approach for a particular UI for a particular data capture application, where I have a bunch of form widgets (EditText's and Spinner's) at the top of a vertical scrolling view, then a number of checked entries (10-200), and then a number of additional widgets at the end.
I am trying to think of the best way to get utilise the efficiency of the ListView (with the view recycling and option of the custom adapter for the checked entries), but the flexibility to include the other widgets before and after the list.
I have eliminated the idea of putting a ListView inside a Scrollview, for the well documented reasons.
I have also considered breaking it into multiple views and using the ViewFlipper, but this does not flow as well for the user experience.
The only other idea I have encountered is to put my non-listview items in as the Listview header and footer. This way I can still use my custom adapter for the listview checked entries, and the rest of the widgets are where I want.
Does this sound like the most efficient and sensible approach? Any comments and advice appreciated.
I have a custom listview with widgets above and below it in my app. ListView without ListActivity
Just put the listview in it's own LinearLayout and it should work perfectly.

Does Android have a Table like Adapter for ListView

I'm using a ListView to show a list of items. These items are in a table format with columns and rows. Is there a table like adapter to make sure all the columns and rows line up? I know this brings in the complexity of how large each column should be, what to do with cut off text, and other things. I'm just curious if there is currently and adapter hiding somewhere for this task. Or maybe even another control?
The point of using ListView is to be able to scale to larger data sets by not having to create and layout views for all of the items up-front. Because of this, your request fundamentally conflicts with how ListView works -- ListView simply doesn't know how all of its items will layout, so there is no way for it to automatically make sure they align in some way.
You can ensure they align yourself just by writing the item layout appropriately. For example, very often in the UI you will have an icon followed by a label. If you ensure the icon is a specific size, then all of the list items will align. If you are dealing with elements that are more dynamic like text, you could do the same thing by enforcing up-front a specific width for those elements.
If you really want to have the UI compute the element sizes dynamically and align all of the rows based on them, that is what TableLayout does. It can do this because it always has all elements there to layout together. If you want to allow scrolling in it, you can wrap that in a ScrollView like another poster suggested. Just be aware that this approach will quickly fall apart as your number of rows increases significantly.
I was able to make TableLayout to behave like ListView (at least visually). Here is my answer.
There is GridView for that, but afaik it doesn't work with columns and rows. Luckily you seem to have been expecting some complexity :)
You can use a ListView or a ListFragment and populate items using each time a single TableRow inside a TableLayout (maybe using android:stretchColumns="0")
you'll have a TableLayout per line, so it's probably inefficient but it does what you are trying to do

Should I use multiple ListViews?

I have a RelativeLayout with different elements. I was planning to have two ListViews on it, but I have noticed there are some problems with scrolling. Since each ListView only shows a maximum of 5 rows should I try to make some kind of custom adapter to merge those ListViews? Or is it better to replace the ListView with a LinearLayout/RelativeLayout and add the rows as I get them manually? (like the first answer in here: android listview display all available items without scroll with static header ).
Which should be the proper way on doing this? or is there another way? Also, each row will have an OnClickListener.
There's two solutions if you'd like to keep your list... list-y, without having to prerender all the row Views like the above solution suggests (which can be slow to render, eats RAM and doesn't scale nicely to more than a screen or two of Views, but is a fine quick solution for smaller lists, though I'd just use a bunch of Views in a LinearLayout in a ScrollView rather than a ListView in that case).
Write a custom ListAdapter, overriding getItemViewType, getViewTypeCount and GetView to inflate the proper kind of view and recycle appropriately for your two types of views. You'll also either need to override getItem to contain custom logic for figuring out which set of source data to look in and to map the data accordingly, or mush the data down into one list of Objects (if you're using an arrayadapter) and cast in the getView method (probably a bit slower than handling it in the getItem without casting).
Just use cwac-merge, a view-and-adapter wrapping adapter. You can put two ListAdapters into a MergeAdapter and set that as your single ListView's adapter.
I had problems with scrolling. I never figured out how to have the ListView share vertical space with a different View, and have a single scrollbar for them both.
I worked around it by having everything that needs to scroll on the layout a row in the ListView.
Adding views as rows to a LinearLayout may have problems scaling up, but I think you'll be OK if you only have 10 rows in total. On 1st gen Android devices it'll probably start to get sluggish around 20 items (depends on Layout complexity obviously). ListView scales up by only inflating views as they come on screen.
So in answer to your question either of the two alternatives you suggest will be OK, but the LinearLayout option will be the easiest to code.

Categories

Resources