Display screen on button click in blackberry eclipse - blackberry-eclipse-plugin

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);

Related

How to wirte Public Dialog addClickListener write back Form TextField

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();
}
}

BrowserComponent with Infiniteloop

How do I add an Infinite progress till the WebPage is fully loaded?
Form hi = new Form("Hi World");
hi.setLayout(new BorderLayout());
final BrowserComponent wb = new BrowserComponent();
hi.addComponent(BorderLayout.CENTER, wb);
final Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
wb.setURL("https://www.codenameone.com");
wb.addWebEventListener("onLoad", new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
hi.show();
ipDlg.dispose();
above is the code I am using.
This won't work since dialog is literally a separate Form. So the browser component will never load and won't show what's going on below.
You can use an InteractionDialog which is just a Container in the layered pane. This means the browser will keep loading and you can draw on top of it. Just add the InfiniteProgress into the InteractionDialog and show it.

Nokia S40 LWUIT Back Button

I'm building a nokia s40 app. I've set this app to be in full screen mode and I notice that when I set this full screen mode, I've lost the native back buttons.
I need to build a back button like the native back button (always on screen, in the bottom right side of the screen). I've tried it with a borderlayout and putting it on the south, but the text from the center container doesn't appears over this...and has transparent background.
If anyone has some sample code, it will be great.
this code simply located a button in the bottom right side of the screen. it's work well.
public void startApp() {
Display.init(this);
Form f = new Form();
//Create a ComponentGroup for all components except backbutton
final ComponentGroup cg = new ComponentGroup();
final Button backButton = new Button("BackButton");
// add this part to your code
f.addOrientationListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Dimension d = new Dimension(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
cg.setPreferredSize(d);
backButton.setX(Display.getInstance().getDisplayWidth() - backButton.getPreferredW());
}
});
//set CoordinateLayout to f
f.setLayout(new CoordinateLayout(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight()));
//Dimension d = new Dimension(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
cg.setPreferredH(Display.getInstance().getDisplayHeight());
cg.setPreferredW(Display.getInstance().getDisplayWidth());
cg.setLayout(new BorderLayout());
cg.addComponent(BorderLayout.NORTH, new Button("NORTH"));
cg.addComponent(BorderLayout.EAST, new Button("ESET"));
cg.addComponent(BorderLayout.WEST, new Button("WEST"));
cg.addComponent(BorderLayout.CENTER, new TextArea("sdsdsd"));
cg.setX(0);
cg.setY(0);
backButton.getStyle().setBgColor(0x2233ff);
backButton.setX(Display.getInstance().getDisplayWidth() - backButton.getPreferredW());
backButton.setY(Display.getInstance().getDisplayHeight() - backButton.getPreferredH() - f.getTitleArea().getLayoutHeight());
f.addComponent(cg);
f.addComponent(backButton);
f.show();
}
you can do like this to any form.
if you want back Button is showed in all forms you can write some OOP programming to do this.
it works well.

Monotouch Hide Keyboard when Navbar is tapped using MonoTouch.Dialog

I am currently using this code to hide the keyboard in a monotouch iOS application when something outside the input elements are tapped.
var tap = new UITapGestureRecognizer ();
tap.AddTarget (() =>{
dvc.View.EndEditing (true);
});
dvc.View.AddGestureRecognizer (tap);
However, I would like to hide the keyboard when the user taps the top Navbar as well. I have seen this in other apps. How would I go about doing that?
Easiest way is to override TouchesEnded in your UIViewController.
This will give you any touch event inside the entire controller.
Then do something like this if you need ignore touches in a certain view:
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
base.TouchesEnded(touches, evt);
if (evt.TouchesForView(viewYouWantToIgnore) == null) {
//Dismiss your keyboard here
}
}

Extend View and Custom Dialogs

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.

Resources