Does anyone know, if you have an array of ImageViews[n][n], how to connect the array to a TableLayout? Furthermore, after it's displayed in the tableLayout, is there a way to tap the images in the table layout and swap places with the adjacent tile with a specific label?
Thanks!
You will just need to construct your TableLayout manually using addView().
You might want to check out GridView which provides an easy way to "link" data using Adapters.
Edit GridView may not work for you because it doesn't specify the number of items per row.
You might also think about making a custom View and rendering your images to a Canvas using the graphics calls in your onDraw() method.
Related
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 can't use listview because this layout will already requires scrolling. So this leaves me at a problem: how to create my tables.
What I know:
The size of the JSON array
I was going to try to make every cell in XML and do a for loop in the code, but my predicament is that I can't findViewById very well, because the R.id.myId names are difficult to account for, and are integers instead of strings. (probably a problem not as large as I am making it).
So here, I know the server call will return a json array with up to 5 objects in it. How can I populate my view?
I am using a LinearLayout for each row, much like I would be preparing a custom list view in preparation.
Insight appreciated.
Is there a specific reason you need it to be a ListView? If not you could try a LinearLayout with a vertical orientation as the container for your list. Just put the container in your xml and you can programatically add the rows that you generate using addView().
I need to show data from a web service with a limited amount of rows and with different number of columns (2-5 according to the ws call).
I don't know what kind of view is better to use: is it better to use a ListView with a dynamic layout using LayoutInflater or should i use a TableLayout as if it was a html page?
You can either go with Gridlayout that would be with more ease or go with TableLayout.
Using a TableLayout provide more structured and user specific look then ListView, you can make modification as per your need. like adding separators with rows, images ot arrows on the different TableRows. so best will be either Girdview or TableLayout.
Things are simple, I want to make a widget with 4 lines and 4 rows in it, on each cell there would be a click-able image and an action set by the user via the Settings page.
The layout is like this:
What layout element is recommended to be used for this scenario ? Should I use a GridView, TableLayout, more Linearlayouts ? Keep in mind that the spacing between items must be the same. I want to make it as light as possible. So, what layout ?
If I decide to use a GridView do you have any simple tutorial about
this? I can't manage to find a way of accessing the GridView from
AppWidgetProvider and set it's Adapter. Thank you.
LE: It seems that GridView is supported starting from Android 3.0.. please correct me if I'm wrong. In this case the only remaining thing to do is add 16 images and for each image add a onClickListener ? Brrr...
If you use a GridView then half of your work is done for you - The only layout and formatting elements you need to consider are on a Global (GridView) and Item level.
Using a GridView will also give your Scrolling functionality and the ability to change your row/columns count based on your device (4x4 on tablet, perhaps 2x8 on a phone).
Creating an extension of BaseAdapter to attach the Grid's children will also give you the flexibility to check items, multi select and will allow you to quickly modify the implementation in future by adding and removing items at will.
If this is simply a 4x4 grid which will always ALWAYS remain the same independent of device and each "Item" will always be the same, Use a RelativeLayout as it will be the most lightweight and efficient ViewGroup.
I have created a custom adapter to display a list, there is an image that is displayed in each row ( the image is the same for all rows, except using an array i am assigning it different values depending on the position). An xml file defines the relative layout that i am using. My problem is that i can either get the entire row to be clickable or nothing at all, I only want this image to be clickable, instead of the entire row. How would i be able to do this ? i am new to android and am pretty much following different tutorials trying to create my list. Any help would be appreciated.
layout is like this :
TEXT:
[Image]
TEXT:
thats wat a row looks like...getting two texts from two different arrays and shows it, a third array is used to link to the image. I just want this image to be clickable instead of the entire row.
Thanks
Android's list component manages clicks per row. This makes it very difficult to achieve what you want to do. Two solutions come into mind:
1) If your list is never very long you could simply use linear layout and scroll view to build the list. This approach won't work if you fill in the list dynamically and you can't be sure that there won't be a very large number of rows as it would use too much memory in that case.
2) Other option is to use ListView but make your text components and images different view types in list ie. break you row into three.
That can be achieved overriding list adapter's getItemViewType(int)
http://developer.android.com/reference/android/widget/Adapter.html#getItemViewType(int)
In this approach you can make the image rows clickable but the text rows not.