水平方向に2つのカスタムボタンを表示し、それらの間にBlackBerryアプリのラベルフィールドを表示します。「 BlackBerryHorizontalFieldManagerアライメント」を見ましたが、うまくいきませんでした。これがBlackBerryで作成したいスクリーンショットです。
この画面用に作成したコードは次のとおりです。
package mypackage;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
/**
* A class extending the MainScreen class, which provides default standard * behavior for BlackBerry GUI applications. */ public final class HelloBlackBerryScreen extends MainScreen { BasicEditField username; PasswordEditField password;
/**
* Creates a new MyScreen object
*/ public HelloBlackBerryScreen() { // Set the linear background. this.getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(0x91e7ff,0x0099CCFF,0x00336699,0x91e7ff));
// SET HEADER OF SCREEN VerticalFieldManager vfm = new
VerticalFieldManager(Manager.USE_ALL_WIDTH); BitmapField header = new
BitmapField(Bitmap.getBitmapResource("header.png"),FIELD_HCENTER);
HorizontalFieldManager hfm = new
HorizontalFieldManager(Field.FIELD_VCENTER |Manager.USE_ALL_WIDTH);
setTitle(header);
hfm.add(vfm); add(hfm);
//SET Container
LabelField usernameTxt = new LabelField("Username:",LabelField.FIELD_TOP);
usernameTxt.setFont(Font.getDefault().derive(Font.PLAIN, 30));
usernameTxt.setMargin(20, 0, 0, 160);
LabelField passwordTxt = new LabelField("Password :",LabelField.FIELD_BOTTOM);
passwordTxt.setFont(Font.getDefault().derive(Font.PLAIN, 30));
passwordTxt.setMargin(10, 0, 0, 160);
username = new BasicEditField(BasicEditField.FIELD_BOTTOM);username.setMargin(10, 110, 0, 160); //username.setMaxSize(getHeight());
username.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3,3, 3), 0x999999, Border.STYLE_FILLED));
username.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
password = new PasswordEditField(); password.setMargin(10, 110, 0,160); password.setBorder(BorderFactory.createRoundedBorder(new
XYEdges(3, 3, 3, 3), 0x999999, Border.STYLE_FILLED));
password.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
ButtonField loginBtn = new ButtonField(" Log-In ", ButtonField.CONSUME_CLICK); loginBtn.setMargin(30, 0, 0,240);
ButtonField recoveryBtn = new ButtonField("Forget Password", ButtonField.CONSUME_CLICK); recoveryBtn.setMargin(10, 0, 0,200);
add(usernameTxt); add(username); add(passwordTxt); add(password);
add(loginBtn); add(recoveryBtn);
loginBtn.setChangeListener(btnlistener); } FieldChangeListener
btnlistener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
//Open a new screen
String uname = username.getText();
String pwd =password.getText();
//If there is no input if (uname.length() == 0 || pwd.length()==0)
Dialog.alert("One of the textfield is empty!");
else if
(uname.equals("user") && pwd.equals("admin"))
UiApplication.getUiApplication().pushScreen(newwelcome());
//Open a
new Screen else
Dialog.alert("Username or password not found!");
}
};
FieldChangeListener btnlistener2 = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
screen if variables are not empty
[1]: http://i.stack.imgur.com/PlDRu.png