I'd just like to ask if it's possible for widgets to have conditional visibility within the layout XML?
Specifically, I have 2 layouts that each have a ListView. I've also implemented a custom layout for the list items.
The custom list item layout has 3 buttons, however, for one of the activities, one of the buttons isn't relevant and must be removed/hidden.
Is it possible to accomplish this in the layout XML? I'd really rather not create another custom list item layout just to remove one button for one activity.
Thanks in advance.
Put in activity a button.setVisibility(View.GONE);
Related
I want to add three textViews in a single button.
I can do it using linearLayout as an XML file and then inflating it to my custom button class but somehow when I set click listener on this type of custom button it won't work.
I desire for a much better option, maybe extending the Android button class and then change it according to my requirement, but unable to inflate my button to my desired views.
Please assist me on how to do this.
Creating LinearLayout and setting style="#android:style/Widget.Button"
Did the trick for me.
You can design your layout with the three textviews as usual. For emulating click, set a StateListDrawable as the background of the root container. Put this in any layout (or use <include>) and attach a clickListener as usual.
You can simply use LinearLayout with 3 textview as its child and set click listener on it. No need to create custom button class. But I do not know exact requirement so need more details for creating custom button class.
I created a layout which has a button. I want to prevent from duplicating the button for each row while I'm using the layout to inflate. How should I do that?
Thanks,
Alireza
I'm not sure what you mean by "inflate" but the button is in the schema of the layout so that has to be taken out of the scope of that tag. Then, you can define another section (container) and have one button per container. If you add more details to your question, I'll elaborate
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!
I have basic knowledge of layouts and so far in my applications I always had one static layout for each Activity. Now Im trying to create a single Activity with a basic framework (Title, some buttons) and a Layout I need to change after clicking a specified button.
Example:
I have a Title bar, a Linear Layout under it and 3 buttons under it. After clicking one of the 3 buttons I change the title text and the button appearance. But I also need to change my Linear Layout between Title bar and buttons. I didnt know how to do this exactly, so I made it Linear Layout in my main.xml, but after clicking one button, I actualy need it to be a Table Layout (or a List View), after clicking another button I need it to be a Relative layout. I hope you get the picture. In all cases I need to add some elements into it (table rows, some views etc.)
My question is, what is the best way to acomplish this? Thanks!
In my app I want to have a button that if the user clicks it
than a new layout is opened within the current (acually the main) layout.
the new layout should not fill all of the screen and parts of the previous layout
should be grayed out.
Any ideas on how to do this ?
You can show a hidden layout within your button's onClick event by calling
view.setVisibility(View.VISIBLE)
You can also fade out view elements or whole views with
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
Note that "view" in the first example is your layout element.. LinearLayout, RelativeLayout, etc. and in the 2nd example, "view" is the element(s) you're trying to gray out.
Follow the answer of SBerg413. And for more information. you can take the relativelayout for the part that you want to hide and display on the button click.
And as like SBerg413 answer. you can hide the respective layout and show the layout you want to display.
Hope it will help you.
Thanks.
you can use a ViewFlipper to achieve what you want, position the viewflipper where the child views should fit (part of the screen you say)..
Inflate the rest of the "child" layouts from other xml, add them to the flipper and switch between them when you want...