2011-06-17 60 views
0

先生您好我米將某個應用中,我陷入了一個問題,請大家幫我出焦點領域...如何獲得在一個頁面即時從服務器獲取數據並顯示,在黑莓

現在我的網頁上的數據使用Focusable來突出顯示它們...現在我的要求是,當重點出現在任何數據上時,它應該改變字段,例如:打印出現焦點的名稱..

以下是在頁面上顯示數據的代碼現在正在處理現場更改,我需要單擊標籤字段....

package com.Tally.app; 

import com.Tally.screenParams.BankList; 
import com.Tally.screenParams.CrDrList; 
import com.Tally.screenParams.SearchList; 

import net.rim.device.api.system.Display; 
import net.rim.device.api.ui.Color; 
import net.rim.device.api.ui.DrawStyle; 
import net.rim.device.api.ui.Field; 
import net.rim.device.api.ui.FieldChangeListener; 
import net.rim.device.api.ui.Graphics; 
import net.rim.device.api.ui.Manager; 
import net.rim.device.api.ui.MenuItem; 
import net.rim.device.api.ui.component.Dialog; 
import net.rim.device.api.ui.component.LabelField; 
import net.rim.device.api.ui.component.Menu; 

import net.rim.device.api.ui.container.HorizontalFieldManager; 
import net.rim.device.api.ui.container.VerticalFieldManager; 
import net.rim.device.api.ui.decor.BackgroundFactory; 

public class LowerCreditors extends VerticalFieldManager implements 
     FieldChangeListener { 
    // class Lower extends 

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


       public int getPreferredWidth() 
        { 
         return 210; // fix width 
        } 




       protected boolean navigationClick(int status, int time) { 


        fieldChanged(this, 0); 
        return true; 
       }; 
      }; 


      LabelField Value = new LabelField(CrDrList.VendorValArr[i]); 

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

      add(hfm); 


     } 



    } 

    protected void paintBackground(Graphics g) { 
     // TODO Auto-generated method stub 
     g.setColor(0xB8E0B8); 

     g.fillRect(0, 0, net.rim.device.api.system.Display.getWidth(), 
       net.rim.device.api.system.Display.getHeight() + 2000); 
     g.setColor(Color.BLUE); 
     super.paintBackground(g); 
    } 

    protected void paint(Graphics graphics) { 
     graphics.setColor(0xB8E0B8); 
     graphics.fillRect(0, 0, Display.getWidth(), 20); 
     graphics.setColor(Color.BLACK); 
     super.paint(graphics); 
    } 

    protected void sublayout(int maxWidth, int maxHeight) { 
     // TODO Auto-generated method stub 

     setExtent(net.rim.device.api.system.Display.getWidth(), 
       net.rim.device.api.system.Display.getHeight()); 
     super.sublayout(net.rim.device.api.system.Display.getWidth(), 
       net.rim.device.api.system.Display.getHeight()); 

    } 

    public void fieldChanged1(Field field, int context) { 
     // TODO Auto-generated method stub 

    } 


    protected boolean abc(int status, int time) { 

     navigationClick(1, 1); 

     Dialog.alert("Called......"); 
      return false; 

    } 


    public void fieldChanged(Field field, int context) { 

     // TODO Auto-generated method stub 
     for (int i = 0; i < CrDrList.VendorNameArr.length; i++) { 

      if (field == CrDrLabels[i]) { 



       String LN = CrDrLabels[i].getText(); 
       // SearchList.cname=cn; 
       CrDrList.cname1 = LN; 

       LabelField cname1 = CrDrLabels[i]; 
       System.out.println("cnnnnnnnnnnnnnn : "+ cname1); 
       CrDrList.selLad = CrDrLabels[i]; 
       System.out.println("Creddddddddddddddrrrrrrr"+CrDrList.selLad); 

       abc(i, i); 

      } 

     } 
    } 
} 

waitng答覆..

+0

如果可能的話,請幫我從這個問題OKK對不起.... – 2011-06-17 12:55:29

回答

2

夫婦的事情你可以做:

  1. 您可以設置每個字段FocusChangeListener,做任何需要在focusChanged()方法來完成。
  2. 使用getFieldWithFocus()getLeafWithFocus()
  3. 覆蓋每一個的LabelField的onFocus()方法

編輯爲您的評論的LabelField

重寫onFocus()。只需添加這對你覆蓋了其他方法:

protected void onFocus(int direction) { 
    //do things that need done when the label gets focus 
} 

而且如果需要,當它失去焦點

protected void onUnfocus() { 
    //do things that need done when the label loses focus 
} 
+0

請給我的代碼,如果可能的正版遊戲我已經試過這種方式也.... – 2011-06-17 13:12:54

+0

沒有它不工作我不是得到解決因爲我想... – 2011-06-17 13:24:19

0

在導航movment做一些嘗試。

protected boolean navigationMovement(int dx, int dy, int status, int time){ 
    System.out.println("field name with focus is...."+getLeafFieldWithFocus()); 
return super.navigationMovement(dx,dy,status,time); 
} 
相關問題