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.
Related
First of all I will explain my scenario.
I have an activity with a linear layout and I am inflating that linear layout with custom views. In the custom view I have a remove button to remove the particular child.
I know to remove the view I have to add an onClick Listener to the button in the custom view. But what I am not sure about is that how can I remove the view from its parent view from that onClick Listener.
I am populating the linear layout from items stored in shared preferences. So I thought first to update the shared preference by removing the string of the particular custom view I am clicking. But I don't know how I cn manage to re-populate the linear layout, since the function is in the parent activity.
I am a complete newbie in android. Thanks in advance
update
I'll make the scenario a little more simple.
I have a custom view with two imagebuttons - update & remove.
If i click in the remove button, then the custom view should be removed from the linearlayout.
And if I click in the update imagebutton, a function of the Activity which hosts the Linearlayout should be called with the text in the customview as a parameter.
How can i do this. I tried many ways, but failed :-(
I found the answer finally :
For the first requirement, ie., to remove the view, I used:
LinearLayout parentLyt = (LinearLayout) RecentSearch.this.getParent();
parentLyt.removeView(RecentSearch.this);
Thanks Very much to Piyush Gupta (#piyush)
For the second option, to access the hosting activity, I used getContext() and casted it to my activity class, then called the method.
Thanks every one who replied.
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);
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!
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
I want to make layout that expands dynamically, like some kind of menu.
It should look like this
http://imageshack.us/photo/my-images/845/dialog.jpg/
Step 1:
When I click on TextView it should inflate the new layout, remove transparent one, and move text to the left side.
Step 2:
When I click again on TextView (it's vertical custom TextView btw) it should go back to Step1
I want to put this layout into custom dialog and it should always be on my right side of the screen?
Any ideas how to solve this?
I can do this with two layouts and changing contentView of dialog on every click, but it seems like a very dirty solution. Is there some nice and fancy way to do this?
The simplest solution is probably just inflating all the Views, set their visibility accordingly, and move the TextView when the user clicks on it.
From the looks of it, it seems like you want to slide between a lot of views by clicking the TextView? If so, you might want to look into something called ViewPager, with a little customization you might be able to archive that.
Create two different layout's mentioned in images like 1) layoutone.xml 2)layouttwo.xml
Now crete on linearlayout in add that layout in your alertdialog. Also add layoutone in that linearlayout by inflating that layout. Now on click of that textview just removeallviews from that linearlayuout & inflate second layout & vice varsa.