如何在黑莓中更改焦点上的字段

时间:2011-06-02 07:29:38

标签: blackberry java-me

您好先生,我正在制作一个应用程序,我遇到了问题请帮助我...

在一个页面中我从服务器获取数据并在页面上显示该数据现在我使用Focusable突出显示它们...现在我的要求是,当焦点出现在任何数据上时,它应该改变以该名称为准的字段哪个焦点存在..

以下是显示页面上数据的代码,现在它正在进行字段更改,我需要点击标签字段....

static LabelField[] CrDrLabels;

    public LowerCreditors() throws Exception {

        super(VerticalFieldManager.VERTICAL_SCROLL);

        CrDrLabels = new LabelField[CrDrList.VendorNameArr.length];

        for (int i = 0; i < CrDrLabels.length; i++) {
            final int t = i;

            VerticalFieldManager hfm = new VerticalFieldManager(USE_ALL_WIDTH) {

                protected void sublayout(int Width, int Height) {

                    // TODO Auto-generated method stub

                    super.sublayout(Width, Height);

                    setPositionChild(getField(0), 15, 0);

                    setPositionChild(getField(1), Display.getWidth()
                            - getFont().getAdvance(CrDrList.VendorValArr[t])
                            - 10, 0);
                }
            };

            CrDrLabels[i] = new LabelField(CrDrList.VendorNameArr[i],
                    LabelField.FOCUSABLE | Field.USE_ALL_WIDTH) {
                protected boolean navigationClick(int status, int time) {
                    fieldChanged(this, 0);
                    return true;
                };
            };

            LabelField Value = new LabelField(CrDrList.VendorValArr[i]);
            CrDrLabels[i].setPadding(0, 170, 0, 0);

            hfm.add(CrDrLabels[i]);
            hfm.add(Value);

            add(hfm);


        }
    }

    public void fieldChanged(Field field, int context) {

        // TODO Auto-generated method stub
        for (int i = 0; i < CrDrList.VendorNameArr.length; i++) {
        getFieldWithFocus();
            if (field == CrDrLabels[i]) {

                String LN = CrDrLabels[i].getText();
                CrDrList.cname1 = LN;

                LabelField cname1 = CrDrLabels[i];
                CrDrList.selLad = CrDrLabels[i];

            }

        }
    }

,其他代码是

menu.add(new MenuItem("View last 5 days transaction", 20, 10) {
            public void run() {
                if(property.Status.equals("online"))
                {
                Viewlast5daystransaction();
                }

                else
                {
                    Dialog.alert("Please login Online to access the data..");
                }
            }

            String LedgerName = CrDrList.cname1;

            private void Viewlast5daystransaction() {
                //Dialog.alert("Last 5 Days Transaction");

                int resCode = 0;

                HttpConnection connection = null;
                try {
                    connection = getConn(property.LedgerDetailsURL);
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    System.out.println(e1.getMessage());
                    e1.printStackTrace();
                }

                try {
                    resCode = connection.getResponseCode();
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                if(resCode==0)
                {
                    Dialog.alert("Internet Connectivity not available.. Please try again later..");

                    TallyA TA;

                    try {
                        TA = new TallyA();

                        UiApplication.getUiApplication().popScreen();
                        UiApplication.getUiApplication().pushScreen(TA);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }

                sPostdata = "{\"tok\":\""
                        + CompanyList.tok;

                System.out.println("Postedddddd Dataaaaaaaaa" + sPostdata);
                try {
                    String response = LedgerSearchReport();

                    System.out.println("response" + response);

                    ParseBankdetails.parsebankdetails(response);

                    System.out.println("response : " + response);

                    if(response != null)
                    {
                    LastFiveDaysCr LF;
                    try {
                        LF = new LastFiveDaysCr();

                        UiApplication.getUiApplication().pushScreen(LF);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    }

                    else
                    {
                        Dialog.alert("No Data..");
                        Creditiors LF;
                        try {
                            LF = new Creditiors();

                            UiApplication.getUiApplication().pushScreen(LF);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                }
                catch (Exception e) {

                    e.printStackTrace();
                }

            }
        });

在这个领域只有我想要而不是场改变应该有焦点改变... 请帮帮我...

1 个答案:

答案 0 :(得分:1)

我认为你应该在“ onFoucus()”方法中实现逻辑,而不是对CrDrLabels [i]使用“ onfieldChanged()”;