I'm making an app where there's one main activity that is a Fragment. I basically have a few tabs and each tab/page layout I want a different layout. For one of them, I want to know if I can dynamically create a table of, say 20-ish rows with X amount of columns. Instead of having to manually create each row inside the layout .axml file.
The reason for wanting to dynamically create it is that I'm obtaining some data from online that I want to automatically put inside a table.
You will only need to create 1 layout for the item and it will be your item 'template' to inflate it into your ListView dynamically. Take a look at this RecyclerView example (which is the improved ListView)
Related
I have one dynamic array that I'm getting it from REST.
If it has 3 arrays inside, I need to put 3 layouts in my view in order to the user can select one of them. Is like inflate a ListView, but creating textview and button in each of them.
How can I make this?
thanks
After reading Dynamically add elements to a listView Android , I understand clearly how to dynamically add row elements to a listView.
However, I have one idea that how to dynamically add column elements to a listview.
For example, there are 2 columns originally. After I click a button, I would like to add one one more column.
Can anyone provide example code?
Thank for all sharing.
Just add rows dynamically, but make a custom view with two different elements... So there'll be two elements on your every view of row. And first, set first items while seconds are invisible and after clicking button set others... So it'll seem that you're adding column...
I need to implement in my android app a component that displays data like in the image bellow:
How I can do this? Behavior(scrolling and other) of this table-component must be as a ListView. Now I have a two-level ListView where "List 1 label" and "List 2 label" are parent nodes. I want place them to left side. Maybe I must use TableLayout where in right column place a ListView?
you can use listview as a main item. on the other side in the getview() method of adapter you can create a dynamic layout depending on the number of items to add to the right side. by going dynamic at runtime depending on the requirement you will be able to generate the ui and place it as a single item. or the other approach you are using is also correct i think, but in that case number of table rows to inflate would get fixed if you are not going for dynamic ui.
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
I am trying to figure out how to load different groupviews dynamically.
I am creating application that will have menu with 4 categories and each category will have several sub-menu items. I have created four LinearLayouts with sub-menu buttons inside (they are separate xml files).
Now I want to display appropriate sub-menu in my main view every time the category is changed.
So far I have:
HorizontalScrollView sView = (HorizontalScrollView)findViewById(R.id.CustomScrollView);
LinearLayout ll = (LinearLayout)findViewById(R.id.category1_menu_layout);
sView.removeAllViews();
sView.addView(ll);
However this doesn't work because the ll for some reason is null(category1_menu_layout is the id of the LinearLayout inside the category1_menu.xml)
Do you have any ideas why that doesn't work? Maybe there is another ways of doing this?
Thanks
Do you have any ideas why that doesn't work?
Because you do not have a widget whose ID is #+id/category1_menu_layout presently defined in your activity.
Maybe there is another ways of doing this?
Use a ListView. Or use an ExpandableListView. Or inflate the categories using getLayoutInflater(). Or create the categories in Java code.