Using a layout inside a layout? - android

Which is the best way to change the content inside a layout by pressing buttons?
I want 6 buttons and different content for each push.
I cannot use tab layout because i already used it so..

I would suggest using the gridview that is set up in API Demos. You can import it in as a new project from the Android SDK.
It works effectively like the list of 'All Apps'. However you can change the way it lays out the buttons/icons/text.

In an app I'm working on, I have a list of message types as buttons. Clicking a button changes the display to a layout for composing the selected message. To do this, I have a FrameLayout for the area I want to change. I reference this view as 'compose_content'. When I want to change the content, I run the following code:
compose_content.removeAllViews();
LayoutInflater.from(activity).inflate(R.layout.new_content,compose_content, true);
This will change the FrameLayout content to the content from the specified layout.

One solution can be to have all the 6 views inside your inflated xml and depending on the button pressed set the visibility of that particular view visible and the rest gone

Related

Android draw outside the view

I would work with a piece of layout that isn't shown, the user must scroll to see what I have did. How can I do it? Can I join 2 different layout in one? I prefer to collocate item as I do with default layout. If it can help, I use Android studio. I prefer use elements without code, adding them from palette. An example :
You can use two different layout in main relative layout & whenever u want child layout just set visibility.
You will want to use a ScrollView for this. From the documentation:
Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display.

Android Views using Templates

I've got multiple screens in my applications, which are nearly the same:
Basically there's a heading on the top and a view at the bottom including buttons. If I click on a button, the text of the heading should change. Then, when clicked on determined buttons, there should appear a second header, under the first one, in some cases a third. Each of them includes buttons. When clicking on a button of the second header, the third header should change, when clicking on the third header, only the content below the headers should change.
My target is also to nest (3) different templates, but to define each of them only for once (in xml). Is there a way to do this?
Don't know, if the image works, here's the link to dropbox.
Your main layout should be 3rd template layout.
You just have to hide the buttons or the button layout using attribute setvisibility="gone" in xml layout and in java when you click the button you can set visiblity to visible and you can also do set text to textview to change the header text to whatever you want on click of the buttons.
Hope this helps you
One solution is to declare different xml Views, which could be included by using the 'include' tag in other xml files.

How to have two layout xml files in a single activity in android

I am developing application in android.What I want is ,my activity should represent two xml layouts files.concept is like,
->when the activity is started it should show one layout(screen)
->when I click on the button exist on the first layout, it should show 2nd layout in the bottom of the screen,keeping first layout visible.
Have both the layout in a single XML. Keep the visibility of the the second layout to secondLayoutObject.setVisibility(View.GONE) initially and then on the click of the button change its visibility to secondLayoutObject.setVisibility(View.Visible).
On method to call two xml files in on activity is by using layoutmanager and assign the screen ratio for both xml files. Use relative layout in both xml. Small code snippet is
RelativeLayout layleft = (RelativeLayout)inf.inflate(R.layout.firstxml,null);
RelativeLayout layright = (RelativeLayout)inf.inflate(R.layout.secondxml,null);
for detail info Layout Reuse help
For this you have to use the concept of visibility. Initially set visibility of second layout as GONE and when you press button set Its visibility True.
you can try use the bellow example:
https://github.com/AdilSoomro/Iphone-Tab-in-Android
this source code to change layout like button click to load another layout!

Nested text view in android,with dynamic content

I want to display a recursive or nested text view at depth of 3 in Android.The text to be displayed is, dynamic coming from web service.
for example:
If I Click on Help(Level 1)
it'll show topics under Help
If I Click on Help_Topic_1(Level 2)
it'll show questions under Help_Topic_1
If I click on this question, say HT_Question_1(Level 3)
it'll show Answer of that question(Level 3)
how to accomplish with this? please guide me.
You should use ExpandableListView. Reference http://developer.android.com/reference/android/widget/ExpandableListView.html
You can call expandGroup and collapseGroup methods for expanding and collapsing on clicks.
the simplest way to do this is to have a nested layout structure. Your root view will contain the button to show level 1 and a child layout and initially be visible. The children's layout visibility will initially be set to "GONE". In the onclick listener for each button you change the visibility of the layout below it to view to "VISIBLE".
This of course is a very simple way of doing it. If you require to have open and close animations you'll need to use a more complex method.

Hiding and showing android layouts - How do you mark active layout?

I'm just writing my first android app and in one layout xml file I have four buttons that will display a different layout when pressed. Instead of creating four seperate screens, I've just put the four layouts in the same layout as the buttons with android:visibility="GONE", and then when a button is pressed, I set it's corresponding layout to being visible.
My question is, is there a best practice or suggested method for keeping track of the active layout so that when a button is pressed you can set the active layout back to visibility="GONE" before making the new one visible. I thought I could just set a string value with the ID of the active layout, but then findViewById wont take the string to get a hold of the layout. Any help or suggestions would be great. Thanks!
Why do you use a string to save the ID of the layout? Can you not just use an int since the ID's are such? Or set the visibility of the layouts from the onClickListener you attached to each button?

Categories

Resources