English 中文(简体)
黑莓中的对象选择字段宽度和高度问题吗?
原标题:ObjectChoiceField width and height issue in BlackBerry?

我在BlackBerry工作一个基于 UI 的应用程序。 UI 如下:

label-1 :   Oject choice field-1
label-2 :   Oject choice field-2
label-3 :   Oject choice field-3
label-4 :   Oject choice field-4
label-5 :   Oject choice field-5

生成此 UI 确实越来越困难。 宽度和高度是我困难的主要问题 。

public HomeScreen() {
    super(MainScreen.USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);

    _dbOperations = new DBOperations();

    _mainVFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
    _mainVFM.setMargin(10, 10, 40, 10);

    _menuFieldVFM = new VerticalFieldManager();
    _menuFieldVFM.setMargin(0, 5, 0, 0);
    _menuDropDownVFM = new VerticalFieldManager();

    ((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createSolidBackground(Constants.BgColorCode));

    XYEdges padding = new XYEdges(1, 1, 1, 1);
    Border roundedBorder = BorderFactory.createSimpleBorder(padding);

    // HEADING
    _headingHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
    _headingLabelField = new LabelField(Constants.Text_heading);
    _headingLabelField.setFont(ApplicationFont.labelFont);
    _headingHFM.add(_headingLabelField);
    _headingHFM.setMargin(0, 0, 20, 0);

    // _productLine LINE
    _productLineLabelField = new LabelField(Constants.Text_ProductLine);
    _productLineLabelField.setFont(ApplicationFont.explainationFont);
    _productLineLabelField.setMargin(8, 0, 0, 0);
    _menuFieldVFM.add(_productLineLabelField);

    int plSetTo1 = 0;
    _productLineOCF = new ObjectChoiceField("", _productLineArray, plSetTo1, Field.FIELD_RIGHT) {

        protected void layout(int width, int height) {
            setMinimalWidth(width - 60);
            super.layout(width, height);
        };
    };
    _productLineOCF.setFont(ApplicationFont.explainationFont);
    _productLineOCF.setChangeListener(this);
    _menuDropDownVFM.add(_productLineOCF);

    // HP
    _HPLabelField = new LabelField(Constants.Text_HP);
    _HPLabelField.setFont(ApplicationFont.explainationFont);
    _HPLabelField.setMargin(25, 0, 0, 0);
    _menuFieldVFM.add(_HPLabelField);

    int hpSetTo1 = 0;
    String data_HP[] = { "Select HP" };
    _HP_OCF = new ObjectChoiceField("", data_HP, hpSetTo1, Field.FIELD_RIGHT) {
        protected void layout(int width, int height) {
            setMinimalWidth(width - 60);
            super.layout(width, height);
        };
    };
    _HP_OCF.setFont(ApplicationFont.explainationFont);
    _HP_OCF.setChangeListener(this);
    _menuDropDownVFM.add(_HP_OCF);

    _RPMLabelField = new LabelField(Constants.Text_RPM);
    _RPMLabelField.setFont(ApplicationFont.explainationFont);
    _RPMLabelField.setMargin(25, 0, 0, 0);
    _menuFieldVFM.add(_RPMLabelField);

    int rpmSetTo1 = 0;
    String data_RPM[] = { "Select RPM" };
    _RPM_OCF = new ObjectChoiceField("", data_RPM, rpmSetTo1, Field.FIELD_RIGHT) {
        protected void layout(int width, int height) {
            setMinimalWidth(width - 60);
            super.layout(width, height);
        };
    };
    _RPM_OCF.setChangeListener(this);
    _menuDropDownVFM.add(_RPM_OCF);

    // VOLTAGE

    _voltageLabelField = new LabelField(Constants.Text_voltage);
    _voltageLabelField.setFont(ApplicationFont.explainationFont);
    _voltageLabelField.setMargin(25, 0, 0, 0);
    _menuFieldVFM.add(_voltageLabelField);

    int volSetTo1 = 0;
    String data_voltage[] = { "Select Voltage" };
    _voltageOCF = new ObjectChoiceField("", data_voltage, volSetTo1, Field.FIELD_RIGHT) {
        protected void layout(int width, int height) {
            setMinimalWidth(width - 60);
            super.layout(width, height);
        };
    };
    _voltageOCF.setChangeListener(this);
    _menuDropDownVFM.add(_voltageOCF);

    // FRAME SIZE
    _frameSizeLabelField = new LabelField(Constants.Text_frameSize);
    _frameSizeLabelField.setFont(ApplicationFont.explainationFont);
    _frameSizeLabelField.setMargin(25, 0, 0, 0);
    _menuFieldVFM.add(_frameSizeLabelField);

    // int iSetTo1 = 0;
    _frameSizeOCF = new ObjectChoiceField("", _frameArray, plSetTo1, Field.FIELD_RIGHT) {
        protected void layout(int width, int height) {
            setMinimalWidth(width - 60);
            super.layout(width, height);
        };
    };
    _frameSizeOCF.setChangeListener(this);
    _menuDropDownVFM.add(_frameSizeOCF);

    _menuMainHFM = new HorizontalFieldManager();

    _menuMainHFM.add(_menuFieldVFM);
    _menuMainHFM.add(_menuDropDownVFM);

    // -OR- LABEL
    _orLabelField = new LabelField(Constants.Text_or);
    _orLabelField.setMargin(20, 0, 0, 0);
    _orLabelField.setFont(ApplicationFont.labelFont);

    // SEARCH BY PART NUMBER
    _SearchByPartNumberField = new LabelField(Constants.Text_PartNoLabel);
    _SearchByPartNumberField.setMargin(20, 0, 0, 0);
    _SearchByPartNumberField.setFont(ApplicationFont.labelFont);

    // ENTER PART NUMBER
    _enterPartNoHFM = new HorizontalFieldManager();
    _enterPartNoLabelField = new LabelField("Enter Part Number: ");
    _partNumberEditField = new EditField();
    _partNumberEditField.setBorder(roundedBorder);
    _enterPartNoHFM.add(_enterPartNoLabelField);
    _enterPartNoHFM.add(_partNumberEditField);
    _enterPartNoHFM.setMargin(20, 0, 0, 0);

    // SAERCH BUTTON
    _searchButtonField = new ButtonField("   Search   ", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
    _searchButtonField.setChangeListener(this);
    _searchButtonField.setMargin(20, 0, 0, 0);

    _checkForUpdates = new ButtonField(Constants.Button_checkForUpdates, ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
    _checkForUpdates.setMargin(10, 0, 0, 0);
    _checkForUpdates.setChangeListener(this);

    _mainVFM.add(_headingHFM);
    _mainVFM.add(_menuMainHFM);
    _mainVFM.add(_orLabelField);
    _mainVFM.add(_SearchByPartNumberField);
    _mainVFM.add(_enterPartNoHFM);
    _mainVFM.add(_searchButtonField);
    _mainVFM.add(_checkForUpdates);
    add(_mainVFM);
}

现在我使用代码,但是没有进展,我处于同一阶段。

public HomeScreen() {
    super(MainScreen.USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);

    _dbOperations = new DBOperations();

    _mainVFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
    _mainVFM.setMargin(10, 10, 40, 10);

    ((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createSolidBackground(Constants.BgColorCode));

    // HEADING
    _headingHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
    _headingLabelField = new LabelField(Constants.Text_heading);
    _headingLabelField.setFont(ApplicationFont.labelFont);
    _headingHFM.add(_headingLabelField);
    _headingHFM.setMargin(0, 0, 20, 0);

    // IMPORTANT CALCULATION
    String productLineString = Constants.Text_ProductLine;
    int charWidth = 0;

    for (int i = 0; i < productLineString.length(); i++) {
        charWidth = Font.getDefault().getAdvance(String.valueOf(productLineString.charAt(i)));
        totalWidth += charWidth;
        System.out.println(totalWidth + "===>>>>>>total width" + i);
    }
    System.out.println(totalWidth + "===>>>>>>total width");
    totalWidth = totalWidth + 10;

    // _productLine LINE
    _productLineLabelField = new LabelField(Constants.Text_ProductLine);
    _productLineLabelField.setFont(ApplicationFont.explainationFont);
    _productLineLabelField.setMargin(8, 0, 0, 0);

    int plSetTo1 = 0;
    _productLineOCF = new ObjectChoiceField("", _productLineArray, plSetTo1, Field.FIELD_RIGHT);

    _productLineOCF.setFont(ApplicationFont.explainationFont);
    _productLineOCF.setChangeListener(this);
    _productHFM = new HorizontalFieldManager(USE_ALL_WIDTH | FOCUSABLE);

    _productHFM.add(_productLineLabelField);
    _productHFM.add(_productLineOCF);

    // HP
    _hp1 = new VerticalFieldManager();

    _HPLabelField = new LabelField(Constants.Text_HP);
    _HPLabelField.setFont(ApplicationFont.explainationFont);
    _HPLabelField.setMargin(25, 0, 0, 0);
    _hp1.add(_HPLabelField);

    _hp2 = new VerticalFieldManager();

    int hpSetTo1 = 0;
    String data_HP[] = { "          Select HP" };
    _HP_OCF = new ObjectChoiceField("", data_HP, hpSetTo1, Field.FIELD_RIGHT | USE_ALL_WIDTH);
    _HP_OCF.setMinimalWidth(totalWidth + 50);
    _HP_OCF.setFont(ApplicationFont.explainationFont);
    _HP_OCF.setChangeListener(this);
    _hp2.add(_HP_OCF);

    _hpHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH) {
        protected void sublayout(int maxWidth, int maxHeight) {
            super.sublayout(maxWidth, maxHeight);
            int x = totalWidth;
            setPositionChild(_hp2, x, 0);
        }
    };

    _hpHFM.add(_hp1);
    _hpHFM.add(_hp2);

    _RPM_HFM = new HorizontalFieldManager();
    // RPM
    _RPMLabelField = new LabelField(Constants.Text_RPM);
    _RPMLabelField.setFont(ApplicationFont.explainationFont);
    _RPMLabelField.setMargin(25, 0, 0, 0);
    _RPM_HFM.add(_RPMLabelField);

    int rpmSetTo1 = 0;
    String data_RPM[] = { "Select RPM" };
    _RPM_OCF = new ObjectChoiceField("", data_RPM, rpmSetTo1, Field.FIELD_RIGHT);
    _RPM_OCF.setMinimalWidth(totalWidth + 50);
    _RPM_OCF.setChangeListener(this);
    _RPM_HFM.add(_RPM_OCF);

    _voltageHFM = new HorizontalFieldManager();
    // VOLTAGE
    _voltageLabelField = new LabelField(Constants.Text_voltage);
    _voltageLabelField.setFont(ApplicationFont.explainationFont);
    _voltageLabelField.setMargin(25, 0, 0, 0);
    _voltageHFM.add(_voltageLabelField);

    int volSetTo1 = 0;
    String data_voltage[] = { "Select Voltage" };
    _voltageOCF = new ObjectChoiceField("", data_voltage, volSetTo1, Field.FIELD_RIGHT);
    _voltageOCF.setMinimalWidth(totalWidth + 50);
    _voltageOCF.setChangeListener(this);
    _voltageHFM.add(_voltageOCF);

    _frameHFM = new HorizontalFieldManager();
    // FRAME SIZE
    _frameSizeLabelField = new LabelField(Constants.Text_frameSize);
    _frameSizeLabelField.setFont(ApplicationFont.explainationFont);
    _frameSizeLabelField.setMargin(25, 0, 0, 0);
    _frameHFM.add(_frameSizeLabelField);

    int fSetTo1 = 0;
    _frameSizeOCF = new ObjectChoiceField("", _frameArray, fSetTo1, Field.FIELD_RIGHT);
    _frameSizeOCF.setMinimalWidth(totalWidth + 50);
    _frameSizeOCF.setChangeListener(this);
    _frameHFM.add(_frameSizeOCF);

    // -OR- LABEL
    _orLabelField = new LabelField(Constants.Text_or);
    _orLabelField.setMargin(20, 0, 0, 0);
    _orLabelField.setFont(ApplicationFont.labelFont);

    // SEARCH BY PART NUMBER
    _SearchByPartNumberField = new LabelField(Constants.Text_PartNoLabel);
    _SearchByPartNumberField.setMargin(20, 0, 0, 0);
    _SearchByPartNumberField.setFont(ApplicationFont.labelFont);

    // ENTER PART NUMBER
    _enterPartNoHFM = new HorizontalFieldManager();
    _enterPartNoLabelField = new LabelField("Enter Part Number: ");
    _partNumberEditField = new EditField();
    _partNumberEditField.setBorder(roundedBorder);
    _enterPartNoHFM.add(_enterPartNoLabelField);
    _enterPartNoHFM.add(_partNumberEditField);
    _enterPartNoHFM.setMargin(20, 0, 0, 0);

    // SAERCH BUTTON
    _searchButtonField = new ButtonField("   Search   ", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
    _searchButtonField.setChangeListener(this);
    _searchButtonField.setMargin(20, 0, 0, 0);

    _checkForUpdates = new ButtonField(Constants.Button_checkForUpdates, ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
    _checkForUpdates.setMargin(10, 0, 0, 0);
    _checkForUpdates.setChangeListener(this);

    add(_pageHeaderHFM);
    _mainVFM.add(_headingHFM);
    _mainVFM.add(_productHFM);
    _mainVFM.add(_hpHFM);
    _mainVFM.add(_RPM_HFM);
    _mainVFM.add(_voltageHFM);
    _mainVFM.add(_frameHFM);
    _mainVFM.add(_orLabelField);
    _mainVFM.add(_SearchByPartNumberField);
    _mainVFM.add(_enterPartNoHFM);
    _mainVFM.add(_searchButtonField);
    _mainVFM.add(_checkForUpdates);
    add(_mainVFM);
}


I am fine with the width of the OCF but height and the position of the OCF must be settled as required. This is the output I am getting with this code.

enter image description here

最佳回答

本答复基于以下链接:

  1. 横向Feltermanger中的 Align Field.

  2. 黑莓横向外地管理员对齐。

尝试以下代码 :

class HomeScreen extends MainScreen {
    public HomeScreen() {
        super(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT | MainScreen.VERTICAL_SCROLL);

        VerticalFieldManager vfmMain = new VerticalFieldManager(Field.USE_ALL_WIDTH);

        // LabelField
        LabelField lblFOne = new LabelField("LabelField One", Field.FIELD_LEFT | Field.FIELD_VCENTER);

        // ObjectChoiceField
        VerticalFieldManager vfmChoiceFieldContainerOne = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_RIGHT);
        final String[] options = new String[] { "Choice One - A very long string.", "Choice B", "Choice C" };
        ObjectChoiceField ocfOne = new ObjectChoiceField("", options, 0, Field.FIELD_RIGHT | ObjectChoiceField.FORCE_SINGLE_LINE);
        vfmChoiceFieldContainerOne.add(ocfOne);

        // Contain a row of LabelField and ObjectChoiceField
        HorizontalFieldManager hfmRowOne = new HorizontalFieldManager(Field.USE_ALL_WIDTH | Field.FOCUSABLE);
        hfmRowOne.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
        hfmRowOne.add(lblFOne);     
        hfmRowOne.add(vfmChoiceFieldContainerOne);      

        vfmMain.add(hfmRowOne);

        add(vfmMain);
    }
}
问题回答

暂无回答




相关问题
PHP Combo Box AJAX Refresh

I have a PHP page that currently has 4 years of team positions in columns on the page. The client wants to select the players in positions and have first, second and thrid choices. Currently the page ...

jquery + ajax + json + fill dropdown list not working

I m pretty sure i am almost there....but i cannot figure out how to iterate through json objects and fill a dropdown list. Here is the js code: My JSON data returned:{"name":"County1","name":"County1"...

Gridviews and DropdownLists

Is it possible to change the data source of a dropdown list in a gridview from another dropdown list selected index changed method in the same gridview? for example I have a dropdown that needs to ...

Adding a new value to the drop down list box

I have a drop down list box which has one of the values to be others. I want to move these value to the last. Please help me with this. The code i am using is as follows ddlAssetsCountryOthersone....

Show hide div using codebehind

I have a DropDownList for which I am trying to show a div OnSelectedIndexChanged but it says OBJECT REQUIRED. I am binding the DataList in that div: aspx: <asp:DropDownList runat="server" ID="...

Why might dropdownlist.SelectedIndex = value fail?

I have a dropdown list that I am binding to a datatable. Here is the code I am using to do it: ddlBuildAddr.DataSource = buildings ddlBuildAddr.DataTextField = "buildingName" ddlBuildAddr....

热门标签