ButtonGroup and ResourceEditor - java-me

We are trying to create an application using the LWUIT Resource Editor as much as possible, it's to say, avoiding creating the UI by code if we can.
We found out there is the possibility to assign a group to a RadioButton by setting the corresponding property on the Resource Editor tool.
So, as we need to implement some functionality for those radio buttons, how can we get the reference to that ButtonGroup instance that the UIBuilder has created (I suppose)?
And yes, considering we are using the Resource Editor tool to generate our midlets, the "custom" code is written on the StateMachine class.
Regards.

AFAIK you can't get ButtonGroup from ResourceEdit#GUI. You can only possible to get RadioButton group name. But possible to add the RadioButton into ButtonGroup through your code. See the following code,
For calling StateMachine() constructor(use this code inside of constructor),
Form form = (Form) this.startApp(resources, null, true);
RadioButton rb1 = this.findRadioButton(form);
RadioButton rb = this.findRadioButton1(form);
ButtonGroup bg = new ButtonGroup();
bg.add(rb);
bg.add(rb1);
bg.setSelected(0);
For calling StateMachine(String resFile) constructor(use this code inside of your MIDlet class),
StateMachine sm = new StateMachine("/Sample.res");
RadioButton rb1 = sm.findRadioButton(Display.getInstance().getCurrent());
RadioButton rb = sm.findRadioButton1(Display.getInstance().getCurrent());
ButtonGroup bg = new ButtonGroup();
bg.add(rb);
bg.add(rb1);
bg.setSelected(0);

Related

Dynamically TextView Or buttons Android Studio

I'm not sure how to do this:
I have a variable that is passed threw an intent to my new activity.
This variable is a Number. That number received threw the intent will be different depending on the user.
So I want to dynamically write buttons or texViews depending on Number variable.
Example : Number = 4;
There is 4 buttons or textviews (with onclick listener each and text written has Button 1, Button 2, et. ).
Example Number = 10;
There is 10 buttons or textviews or etc. (with onclick listeners each).
Not sure how I can approach this problem
You can create new dynamic views something like that:
Button myButton = new Button(this);
myButton.setText("Push Me");
LinearLayout ll = (LinearLayout)findViewById(R.id.yourLinearLayoutId);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
// with addView method you say to your app when you want to add this view inside on your LinearLayout view
ll.addView(myButton, lp);

Add tree component to OverFlowMenu

I am using codename one to create an application, and i am in front of a situation that is making me use the "tree component" in the pop-up of the OverFlowMenu
how can i do that?
That won't work. The overflow menu uses a renderer approach and isn't very customizable.
Instead add a command to the right side of the toolbar and show a popup dialog pointing at that button e.g.:
popupCommand = toolbar.addMaterialCommandToRightBar("", FontImage.MATERIAL_MORE_VERT, e -> showPopup());
private void showPopup() {
Button b = toolbar.findCommandComponent(popupCommand);
Dialog popup = new Dialog(new BorderLayout());
popup.add(BorderLayout.CENTER, new Tree());
popup.showPopup(b);
}

Switch checkbox text and component

I want to create checkbox with text in the left side and the checkbox component on the right side. How I can switch their place?
CheckBox cb = new CheckBox("Show on Startup");
In JavaFX 8, you can do it like this:
Label lb = new Label("left check");
lb.setGraphic(new CheckBox());
lb.setContentDisplay(ContentDisplay.RIGHT); //You can choose RIGHT,LEFT,TOP,BOTTOM
There might be an easier way, but you can use a label and wrap it with the CheckBox in a HBox:
HBox box = new HBox();
CheckBox cb = new CheckBox();
Label text = new Label("Show on Startup");
box.getChildren().addAll(text, cb);
box.setSpacing(5);
It would be nice if the CheckBox considered the box as its "content" like some of the other controls based on Labeled. Then the contentDisplayProperty could be set to ContentDisplay.RIGHT to achieve this. A nice side-effect would be that we could change the rendering of the box with a setGraphic() call.
As of my release (1.8 EA b129), CheckBox doesn't work that way.

How to construct widget programmatically with style applied

To create for instance a button you can use the constructor:
new Android.Widget.Button(MyActivity.Window.Context);
But if you want to do that and apply styling you need to use:
new Android.Widget.Button(MyActivity.Window.Context, AttrSet);
where the AttrSet is an AttributeSet for the styling.
I have defined a style for my button in Resources/values/styles.xml and I then want to apply the style to the button in the constructor. I know following is not working:
System.Xml.XmlReader XmlRdr = MyActivity.Resources.GetXml(Resource.Style.MyButtonStyle);
var AttrSet = Android.Util.Xml.AsAttributeSet(XmlRdr);
Android.Widget.Button MyButton = new Android.Widget.Button(MyActivity.Window.Context,AttrSet);
But how can I then construct my button and apply a style from my resources in a way similar to the above?

ContentPanel AutoSize gxt

I am implementing a user interface using gxt. I have mainForm class with TabPanel.
TabPanel has few TabItems. On orderManagmentTabItem I have a ContentPanel.
TabPanel mainFormTab = new TabPanel ();
mainFormTab.setAutoHeight(true);
mainFormTab.setAutoWidth(true);
TabItem orderManagmentTabItem = new TabItem("TabItem 1");
orderManagmentTabItem.setAutoWidth(true);
orderManagmentTabItem.setAutoHeight(true);
OrderManagmentTabPanel orderManagmentTabPanel = new OrderManagmentTabPanel(); //contentpanel
orderManagmentTabItem.add(orderManagmentTabPanel);
TabItem warehouseManagmentTabItem = new TabItem("TabItem 2");
warehouseManagmentTabItem.setAutoWidth(true);
warehouseManagmentTabItem.setAutoHeight(true);
So I want to set Autozise to orderManagmentTabPanel, but can't do this. I write setAutoHeight(true) and setAutoWidth(true) in orderManagmentTabPanel class, but whet I run my app orderManagmentTabPanel is empty.
Than I tried to set autosize after creating OrderManagmentTabPanel copy
TabItem orderManagmentTabItem = new TabItem("TabItem 1");
orderManagmentTabItem.setAutoWidth(true);
orderManagmentTabItem.setAutoHeight(true);
OrderManagmentTabPanel orderManagmentTabPanel = new OrderManagmentTabPanel(); //contentpanel
orderManagmentTabPanel.setAutoWidth(true);
orderManagmentTabPanel.setAutoHeight(true);
orderManagmentTabItem.add(orderManagmentTabPanel);
But didn't help also
Also tried to implement TabItem class without ContenPanel and add it to mainFormTab, but also didn't work.
How can I make my TabItem to be autosized?
Thx
OK so I believe you mean (correct me if I am are wrong) you have a panel on a tab item and are trying to ensure it takes 100% of the space?
try setting a layout for example
orderManagmentTabItem.setLayout(new FillLayout()); //Sounds like what your after

Resources