I have a dynamically populated TableLayout.
I'm developing for GoogleTV so I need to make the rows in the TableLayout selectable by the remote D-Pad. How can I achieve that?
Am I using the wrong approach here? Should I use a GridView instead? Or maybe ListView Adapter?
I've tried to find examples and similar questions but without success.
Thanks for the help!
How can I make the rows user selectable (and clickable)?
I don't know what do you understand by selectable. To make it clickable just add a OnClickListener to each of your TableRows. To visually signal the user that the row is clickable(like a Button does it when it's pressed) then use a selector drawable for the TableRow's background.
Am I using the wrong approach here? Should I use a GridView instead?
Or maybe ListView Adapter?
A GridView no, but a ListView is a good candidate. If the table doesn't increase past the size you mention(10 x 3) you could use a simple TableLayout. If you know the TableLayout is likely to need to be scrolled(if it needs to be in a ScrollView) then a ListView will be more efficient.
Related
I want to build one activity with two listviews. One that scroll horizontally. One that scroll vertically. The two adapter attached are customized with image and text and load their data from two different sqlite tables.
i've googled for two/three months without result... there's no example that answer to my question
How can i do?
Sorry for my poor english
Gianni Maiorani
The Android SDK does not provide a horizontally scrolling ListView. You can use an open source HorizontalListView.
See the BaseAdapter and CursorAdapter for populating your ListViews with child views that contain image/text.
here is a good example for horizontal list view
http://www.dev-smart.com/archives/34
as for the vertical listview i think there will be no problem in it
I'm trying to implement an irregular gridview for my Android app. I've defined the gridview to show 2 columns but I need to show just 1 column at the first row. Is it possible using a DataAdapter?
I don't think you can accomplish this with a gridview. The adapter simple provides the data, but the view decides how to lay it out. If your requirements allow you to make the number of columns constant, then maybe you can use the gridlayout instead. I'm thinking you could try to do you layout like the google currents app.
Gridview and ListView are super useful if you have 1000's of items since it reuses views as it scrolls. If you have lots a items in your grid, then I would probably try to use the GridView or ListView to accomplish your goal. Maybe you have to get your requirement changed. Another option is to use a ListView, but sub-divide each row into 2 columns.
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
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".
There is a requirement to have not-so-trivial dynamic list, each record of which consists of several columns (texts, buttons). It should look something like:
Text11 Text12 Button1 Button2
Text21 Text22 Button1 Button2
...
At first obvious way to accomplish that seemed to be TableLayout. I was expecting to have layout/styling data specified in res/layout/*.xml and to populate it with some dataset from java code (as with ListView, for which its possible to specify TextView of item in *.xml and bind it to some array using ArrayAdapter). But after playing for a while, all I found to be possible is fully populating TableLayout programatically. Still, creating TableRow by TableRow and setting layout attributes directly in java code doesn't seem elegant enough.
So the question is: am I at the right path? Is TableLayout really best View to accomplish that? Maybe it's more appropriate to extend ListView or something else to meet such requirements?
Using ListView and ArrayAdapter you can do more complicated layouts than just a TextView. You could specify a LinearLayout with 2 TextViews and 2 Buttons for each row in the List.
here's a similar question
Android: ListView elements with multiple clickable buttons
IMHO it depends on the amount of your data you need to render.
Build layout dinamically via inflate/addView is a quite simple task but is
also more slow than using a custom adapter. with a custom adapter you can
reuse the convertView parameter and then set the values more efficiently