adding buttons dynamically in android - android-layout

I'm new to android development and needs help here.I want to create a layout where buttons are added dynamically.In this the no of buttons to be added are decided on the fly.(at run time) i.e depending upon the number return by server i want to add buttons.below is the layout i want to create.Please suggest me suitable solution.I was trying creating this layout with table layout.Thank You
http://i.stack.imgur.com/tbrEq.jpg

Read in your array of buttons and initialize your empty layout (i.e. setContentView). Then, create your buttons using the ImageButton constructor and call .addView(btn) from the layout where you want to insert the button. Don't forget to set any layout parameters you need.

Related

Adding Image button after Add button is clicked (Android Studio Java)

Is it possible in Android studio to produce an Image Button after I clicked a button like Add Button. If yes, how? I want to make an attendance app wherein if the user clicks Add Class an image button will appear
We have no idea of which layout of you are using as the parent. But, for the best results of my answer, linear layout is advised.
The thing you are trying to achieve is trying to create dynamic elements.
For this, you can create an instance of the ImageButton class and then add it to you layout. This can be dont as follows:
//inside onclick of the add button
ImageButton newView = new ImageButton(context);
parentView.addView(newView);
You can add customisations to the view before adding it to the view.

How to dynamically create layouts in android studio depending upon the user's input?

So I'm trying to make an event organization app. The user needs to be able to manage multiple events at the same time. So, if he clicks on 'add event', I must be able to dynamically create a new layout folder for that respective event. How do I go about doing so?
It is not possible to "dynamically create a new layout folder for that respective event" but according to your requirement u can generate views dynamically according to your requirement or inflate a layout
(inflate layout)
1>How to inflate one view with a layout
generate view dynamically from code
2>Dynamically add textViews to a linearLayout
Hope this may help you

How can I change toolbar runtime in MFC Visual C++ 2010

I have two toolbars desgined of equal size and equal number of buttons.
Now based on some condition in code I want to change toolbars run time.
My prject is MDI application built in Visual C++2010 MFC.
Please help as early as possible.My application uses CMFCToolbar
If you are using CMFCToolbar you can just call: CMFCToolbar::GetCommandButtons (a static function). You get an Object array of all buttons in your system and you can change them accordingly (SetToolTip, SetImage ...)
The problem is that CMFCToolbar is variable and buttons can be inserted and dragged around. SO you need the access via GetCommandButons.
If you are using the classical CToolBar class the easiest way is just to add the button, so it always exists in the toolbar and in the bitmap.
If the button should not be visible at startup you just call DeleteButton with the index you receive from CommandToIndex.
To change the button you can just use SetButtonInfo.
If you need the button again, just call InsertButton, with the index where you want to have this button.You may save the previous index and used bitmap index before you delete it.

how to remove default graphic assigned to a control (like buttons and checkboxes) before setting new graphic to that control in java fx scene builder?

i am making a java desktop application using javafx. For gui building i am using scene builder 2.0.
Everything is just perfect as expected just 1 thing. I want to customize the buttons. i want to assign a custom graphic to a button.
When i use [button.setgraphic(node)] , this statement set the new graphic to the button but default graphic of button also remains present as well.
I just want to remove the default graphic and then want to assign the new (custom) garaphic to a control like buttons and radio buttons in javafx. 1 thing again i must tell that i am using scene builder for building gui.
How can i achieve this ?
thanks in advance....
Below is the screen-shot of current occuring situation, .....
Here i have made a button using javafx scene builder , and then in the controller of the fxml file (.java file) i am trying to set the image (shown in orange box in snapshot) to that button by using setGraphics property of button ..... i just need that button to be of following shape ...
You'd better customize your button via CSS. Here goes tutorial. What you are trying to do is to modify button picture (which is empty by default). I guess this wasn't your exact purpose.
button.setGraphic(null)
// worked for me.

How to create an custom View for ListView?

How to create an custom ListView? I have Adapter, but I don't understand how to create an View like ListView of the Facebook, or App for SMS native from device... I'm needing background for TextView, this background, will have an arrow pointing left or right, I tried to create a View using canvas, but it is very difficult...
Every line in the listView of a layout which can be as complex as you want.Just you need an extra xml file for managing you custom layout (it should be contains widgets,fields,images etc as your design ) and the adapter would inflate this layout file for each row in its getView () method and assign the data to the individual views in the row .

Resources