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
Related
I can use multiple recyclers views in xml and assign separate ids and populate them as I want with different adapters and so on.
But I have to create recycler view in xml and initialize in Java and populate them with respective name.
Is there some other means to do. Like with include layout using loops. Can you guyz suggest something.
Like play store has multiple horizontal scrolling layout one below the other just like that.
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)
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 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.
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.