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().
Related
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.
I am trying to create a screen where I get two items from SharedPreferences and display them to the screen, and then display a list via an adapter.
What I am not sure about is how to structure the layout xml file for this. Any suggestions how to do that?
Thanks!
You can have the main layout with a listview. Then you can have a sub layout for each row of your list. This row layout, let's call it row_layout.xml may have two text areas if your items are text or it may have a text area and a checkbox button if that's what you want. Basically, whatever you want to display in a single row of your list.
Read up a tutorial, here's one: http://www.vogella.de/articles/AndroidListView/article.html
Take a look # MergeAdapter, you can also create a view only listitem and add these item as header to the list
I am not sure what you mean. Are you asking for examples of layouts with two textviews that can be updated via sharedprefs, with a ListView in the activity? Or just suggestions? An easy way to get started would be to use the Eclipse Android plugin that has a layout designer in it. Here is a tutorial on how to use it http://mobile.tutsplus.com/tutorials/android/android-layout/ Its pretty easy and straight forward.
I want to create a UI as shown in the below link:
http://i53.tinypic.com/sxksx5.jpg
According to me there can be the following approaches to do it.
There are two tables in this image. The above table should be made in the following way:
One row with two textview in one xml file. Now Inflate this UI using LayoutInflater. Draw It using a loop and set the text according to requirement.
The below table should be made in the following way:
How to make a dynamic table layout using XML
see the above link where It is advised that the 2nd table should be made using the listview.
Now I am confused that this can be made using gridvew, tablelayout, listview. Which one I should prefer and why? In my previous projects I have made this kind of UI almost in the coding. But I believe that a little change in the UI will require lot of change in the code. So I want to make the current UI using the xml. But dont know what approach would be best.
I'd suggest using a ListView. Subclass it and overload the getItem() method to render each column of the table row. You can then easily bind the listview to your data sources. you'll need to create an XML layout resource to describe a row of the table.
To show one table above another, put the listviews inside a RelativeLayout and specify attributes to position them relative to each other.
http://developer.android.com/reference/android/widget/ListView.html
http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
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.
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.