My Monomac project has 2 forms (Form/Views): Mainwindow and form2. (I created form2 using: New -> monomac -> Cocoa View with controller > name is : form2)
On the MainWindow form I have a button. I want to make form2 show/visible when I click that button.
Action when button is clicked is: a1. This is my code :
partial void a1 (NSObject sender)
{
Console.WriteLine ("a1 call form2");
var f1 = new form2Controller();
f1.LoadView();
}
I want to show form2 once the view is loaded, what must I do?
If you've created a "Cocoa Window with controller", then you want to do this to show the window:
f1.Window.MakeKeyAndOrderFront();
If you've created a "Cocoa View with controller", then you have to hook up your window that you added to the xib to an outlet, then call it like:
f1.MyOutletForTheWindow.MakeKeyAndOrderFront();
To make a window visible, you will need to call the ShowWindow method of the view controller.
partial void a1 (NSObject sender)
{
Console.WriteLine ("a1 call form2");
Form2Controller form = new Form2Controller();
form.ShowWindow(this);
}
Related
I’m a beginner, I can’t pass this level, please help.
I have a lot of forms with TextField (cust_no, cust_name), each with a button on the right,
press the button
A dialog can be display custom record, after selecting the required customer,
Write the selected cust_no, cust_name back to the Text_Field of Form.
I hope to write dialog as a public class, so that many class Forms can use this function, and can also smoothly write cust_no and cust_name back to their respective Form TextField.
In addition to backfilling cust_no,cust_name TextField for some Forms, some also need to query the consumption amount and write back the specified cust_amt TextField.
My trouble is that form button.addClickListener open a dialog,
Dialog’s Button_OK.addClickListener cannot know how I want to write back Form TextField and some have special query mechanisms, how to customize
Without seeing exactly how your code is structured, I can only give a quite generic answer. What you need is typically that something associated with the button for opening the dialog can know what to do with the result from the dialog, and it can also configure the dialog's OK button to carry out that action.
public class HelloWorldView extends VerticalLayout {
public HelloWorldView() {
TextField customerNumberField = new TextField("Customer number");
TextField customerNameField = new TextField("Customer name");
Button nameDialogButton = new Button("Open dialog", dialogOpenClick -> {
showDialog(customer -> {
customerNumberField.setValue(customer.getNumber());
customerNameField.setValue(customer.getName());
});
});
add(customerNumberField, customerNameField, nameDialogButton);
}
private void showDialog(Consumer<Customer> selectionAction) {
Select<Customer> customerSelect = new Select<>(new Customer("1", "Customer 1"),
new Customer("2", "Customer 2"));
customerSelect.setTextRenderer(customer -> customer.getName());
Dialog dialog = new Dialog();
dialog.add(customerSelect);
dialog.add(new Button("Select customer", click -> {
Customer selectedCustomer = customerSelect.getValue();
if (selectedCustomer != null) {
selectionAction.accept(selectedCustomer);
}
dialog.close();
}));
dialog.open();
}
}
I have an Android application with a dialog and a few buttons inside.
I want to reuse the dialog for different purposes and looking for a way to call the button from a separate class and define an action event for it.
Creating a test class, I managed to define an action event for a button inside a form, but the same code does not work for a button inside a dialog, and I can't get my head around why it is not working for the dialog.
Below is what I already have. Any suggestions would be appreciated.
public Class One {
Test test = new Test();
test.testOne(); // this is working : button prints
test.testTwo(); // this is not working : button does not print
buttonTest = test.getTestButton();
buttonTest.setText("Hello World"); // not working for a button in a dialog
buttonTest.addActionListener(l-> { // prints when the button in a Form
System.out.println("try"); // does not print when the button is in a dialog
});
}
public class Test {
Dialog dialog = new Dialog();
Form form = new Form();
Button button;
public void testOne() {
button = new Button("Test");
form.add(button);
form.show();
}
public void testTwo() {
button = new Button("Testing");
dialog.add(button);
dialog.show();
}
public Button getTestButton () {
return button;
}
}
You add the action listener after showing the form and dialog. This isn't a problem for the form since the forms show method will continue. But a dialogs show() method will block.
Two solutions:
Move the listener binding higher in the code (before the show) that would be a problem since the button doesn't exist yet so you will need some refactoring.
Change the show() call on the dialog to showModless()
I recently started creating an app for blackberry. I want the app to display a screen (Let's say it's called "InfoScreen") but as I said i am still very new to this. What code will I have to use if I want the "InfoScreen" to be show when the button "buttonInfo" is clicked?
Here is some code I used to create the button that is might relevant to this question.
//Create button
ButtonField buttonInfo = new ButtonField("Information", Field.FIELD_HCENTER);
//Center buttons
VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vfm.add(buttonInfo);
add(vfm);
What code will have to be used for both touch-screen devices and those that use the track-pad?
Thanks
Try this:
FieldChangeListener infoListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().pushScreen(new InfoScreen());
}
};
buttonInfo.setChangeListener(infoListener);
I am developing an ios app in xamarin .How to display a subview(i have used xcode IB for creating a subview) when a button is clicked.Then when i click the same button, again subview must be displayed.If button is pressed 3 times, 3 subviews must be displayed.
In a very common way it will be something like that:
yourButton.TouchUpInside += (object sender, EventArgs e) => {
var newView = new UIView();
// do some stuff with your view here
this.Add (newView);
};
I am working on a game where I am extending the view and performing operations in the class. I need to have a popup in the game which will have 3 buttons inside it. I have managed to have the popup show-up using custom dialogs but when I configure the onClick as follows:
private void popUp() {
Context mContext = getContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_fullimage_dialog);
dialog.setTitle("Cheese Market");
Button one = (Button)findViewById(R.id.firstpack);
one.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
cheeseLeft = cheeseLeft + 10;
masterMoveLock = false;
return;
}
});
}
It force closes giving a nullpointerexeption even though it is defined in the custom_fullimage_dialog layout.
Can someone help me figure out how to have the button click detected in this scenario?
Thank you.
Try calling dialog.findViewById instead.
You're setting the contentView for the dialog, but by calling findViewById you're looking for it under your activity's content view.