2013-04-11 29 views
0

大家好,我在屏幕上工作,屏幕高度減少後單擊CheckBox(當更改偵聽器調用時)。 下面是代碼: -點擊複選框後屏幕高度降低

public class IA_SearchScreen extends MainScreen implements FieldChangeListener 
{ 

    private CheckboxField ch1; 
    private CheckboxField ch2; 
    private CheckboxField ch3; 

    private CheckboxField r1; 
    private CheckboxField r2; 
    private CheckboxField r3; 

    private boolean togle_r1 = true; 
    private boolean togle_r2; 
    private boolean togle_r3; 

    private AutoTextEditField iaDescriptionEditField; 
    private AutoTextEditField streetEditField; 
    private AutoTextEditField postCodeEditField ; 
    private AutoTextEditField radiusEditField ; 

    private Bitmap filterButton_F = Bitmap.getBitmapResource("filter_ focus.png"); 
    private Bitmap filterButton_N = Bitmap.getBitmapResource("filter_Unfocuss.png"); 
    private int temp_mgr_Height = 0; 

    private StatusManager status_Manager; 
    private ImageButton map_Button; 
    private ImageButton favorite_Button; 
    private ImageButton search_Button; 

    private Calendar calendar; 

    private LabelField _startDateLabelField; 
    private LabelField _startTimeLabelField; 

    private LabelField _endDateLabelField; 
    private LabelField _endTimeLabelField; 

    private String[] street_Array; 
    private String[] postCode_Array; 


    private String SearchString  = Global.EMPTY; 
    private String DisruptionsType = Global.EMPTY; 
    private String Lat    = Global.EMPTY; 
    private String Long    = Global.EMPTY; 
    private String Radius   = Global.EMPTY; 
    private String Severity   = Global.EMPTY; 
    private String StartDate  = Global.EMPTY; 
    private String EndDate   = Global.EMPTY; 
    private String PostCode   = Global.EMPTY; 
    private String StreetName  = Global.EMPTY; 
    private String AllDates   = Global.EMPTY; 


    private VerticalFieldManager _workSpace ; 

    public IA_SearchScreen() 
    { 
     super(Screen.USE_ALL_HEIGHT); 

     _workSpace = (VerticalFieldManager)getMainManager(); 

     /** 
     * Initialize Screen Components 
     * */ 



     iaDescriptionEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE) 
     { 
      protected void layout(int width, int height) 
      { 
       super.layout(width, height); 
       setExtent((Global.Display_Width - 40), getHeight()); 
      }; 
      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 

       super.paint(graphics); 
      } 
     }; 
     iaDescriptionEditField.setFont(Global.arialFont_Plain_16); 

     SizedHFM _source0 = new SizedHFM(Global.Display_Width -30); 
     _source0.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true); 
     _source0.add(iaDescriptionEditField); 


     HorizontalFieldManager hfm_0 = new HorizontalFieldManager() 
     { 
      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.setExtent(maxWidth, maxHeight); 
       Field f = getField(0); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 

       setPositionChild(f, 10, 25); 
       temp_mgr_Height = getPreferredHeightOfChild(f) +20; 

       f = getField(1); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 
       //setPositionChild(f, Global.Display_Width -70, 25); 
       setPositionChild(f, Global.Display_Width -55, 25); 

       setExtent(maxWidth,temp_mgr_Height + 35); 
      }; 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.setFont(Global.arialFont_Bold_16); 
       graphics.drawText("Search by Incident or Accident Description", 15, 5); 

       graphics.drawRect(5, 1, getWidth()-10, getHeight()-2); 
       super.paint(graphics); 
      } 
     }; 

     hfm_0.add(_source0); 
     hfm_0.add(new LabelField()); 

     /** 
     * StreetEditField Manager START 
     * */ 
     streetEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE) 
     { 
      protected void layout(int width, int height) 
      { 
       super.layout(width, height); 
       setExtent((Global.Display_Width - 40), getHeight()); 
      }; 
      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 

       super.paint(graphics); 
      } 
     }; 
     streetEditField.setFont(Global.arialFont_Plain_16); 

     SizedHFM _source = new SizedHFM(Global.Display_Width - 65); 
     _source.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true); 
     _source.add(streetEditField); 

     ImageButton btn_go_streetEditField = new ImageButton(filterButton_N , filterButton_F) 
     { 
      protected boolean navigationClick(int status, int time) { 
       fieldChangeNotify(1); 
       return true; 
      } 
     }; 

     btn_go_streetEditField.setChangeListener(new FieldChangeListener() 
     { 
      public void fieldChanged(Field field, int context) 
      { 
       street_Invoke(); 
      } 
     }); 


     HorizontalFieldManager hfm_1 = new HorizontalFieldManager() 
     { 
      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.setExtent(maxWidth, maxHeight); 
       Field f = getField(0); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 

       setPositionChild(f, 10, 25); 
       temp_mgr_Height = getPreferredHeightOfChild(f) +20; 

       f = getField(1); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 
       //setPositionChild(f, Global.Display_Width -70, 25); 
       setPositionChild(f, Global.Display_Width -filterButton_N.getWidth()-10, 25); 

       setExtent(maxWidth,temp_mgr_Height + 35); 
      }; 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.setFont(Global.arialFont_Plain_16); 
       graphics.drawText("Street", 15, 5); 

       graphics.drawRect(5, 1, getWidth()-10, getHeight()-2); 
       super.paint(graphics); 
      } 
     }; 

     hfm_1.add(_source); 
     hfm_1.add(btn_go_streetEditField); 

     /** 
     * StreetEditField Manager END 
     * */ 


     /** 
     * PostCodeEditField Manager START 
     * */ 

     postCodeEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE) 
     { 
      protected void layout(int width, int height) 
      { 
       super.layout(width, height); 
       setExtent((Global.Display_Width - 40), getHeight()); 
      }; 
      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 

       super.paint(graphics); 
      } 
     }; 
     postCodeEditField.setFont(Global.arialFont_Plain_16); 

     SizedHFM _source1 = new SizedHFM(Global.Display_Width -65); 
     _source1.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true); 
     _source1.add(postCodeEditField); 

     ImageButton btn_go_postCodeEditField = new ImageButton(filterButton_N , filterButton_F) 
     { 
      protected boolean navigationClick(int status, int time) { 

       fieldChangeNotify(1);  
       return true; 
      } 
     }; 

     btn_go_postCodeEditField.setChangeListener(new FieldChangeListener() 
     { 
      public void fieldChanged(Field field, int context) 
      { 
       postCode_Invoke(); 
      } 
     }); 


     HorizontalFieldManager hfm_2 = new HorizontalFieldManager() 
     { 
      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.setExtent(maxWidth, maxHeight); 
       Field f = getField(0); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 

       setPositionChild(f, 10, 25); 
       temp_mgr_Height = getPreferredHeightOfChild(f) +20; 

       f = getField(1); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 
       //setPositionChild(f, Global.Display_Width -70, 25); 
       setPositionChild(f, Global.Display_Width - filterButton_N.getWidth()-10, 25); 

       setExtent(maxWidth,temp_mgr_Height + 35); 
      }; 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.setFont(Global.arialFont_Plain_16); 
       graphics.drawText("Post code", 15, 5); 

       graphics.drawRect(5, 1, getWidth()-10, getHeight()-2); 
       super.paint(graphics); 
      } 
     }; 

     hfm_2.add(_source1); 
     hfm_2.add(btn_go_postCodeEditField); 


     /** 
     * PostCodeEditField Manager END 
     * */ 

     radiusEditField = new AutoTextEditField("" , "", 5, EditField.NO_NEWLINE |AutoTextEditField.FILTER_INTEGER) 
     { 
      protected void layout(int width, int height) 
      { 
       super.layout(width, height); 
       setExtent((Global.Display_Width - 40), getHeight()); 
      }; 
      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 

       super.paint(graphics); 
      } 
     }; 
     radiusEditField.setFont(Global.arialFont_Plain_16); 

     SizedHFM _source3 = new SizedHFM(Global.Display_Width -30); 
     _source3.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true); 
     _source3.add(radiusEditField); 


     HorizontalFieldManager hfm_3 = new HorizontalFieldManager() 
     { 
      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.setExtent(maxWidth, maxHeight); 
       Field f = getField(0); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 

       setPositionChild(f, 10, 25); 
       temp_mgr_Height = getPreferredHeightOfChild(f) +20; 

       f = getField(1); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 
       //setPositionChild(f, Global.Display_Width -70, 25); 
       setPositionChild(f, Global.Display_Width -55, 25); 

       setExtent(maxWidth,temp_mgr_Height + 35); 
      }; 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.setFont(Global.arialFont_Bold_16); 
       graphics.drawText("Radius (in Meters)", 15, 5); 

       graphics.drawRect(5, 1, getWidth()-10, getHeight()-2); 
       super.paint(graphics); 
      } 
     }; 

     hfm_3.add(_source3); 
     hfm_3.add(new LabelField()); 


     /** 
     * Start Date & Time 
     * */ 



     _startDateLabelField = new LabelField("") 
     { 

      protected void layout(int width, int height) { 
       super.layout(150, 25); 
       super.setExtent(150, 25); 
      } 

      public boolean isFocusable() { 
       return true; 
      } 

     }; 



     _startTimeLabelField = new LabelField("") 
     { 
      protected void layout(int width, int height) { 
       super.layout(150, 25); 
       super.setExtent(150, 25); 
      } 

      public boolean isFocusable() { 
       // TODO Auto-generated method stub 
       return true; 
      } 
     }; 



     HorizontalFieldManager startDateNTimeManager = new HorizontalFieldManager() 
     { 

      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70); 
       Field f = getField(0); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 

       setPositionChild(f, 20, 30); 
       temp_mgr_Height = getPreferredHeightOfChild(f) +20; 

       f = getField(1); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 
       //setPositionChild(f, Global.Display_Width -70, 25); 
       setPositionChild(f, Global.Display_Width -120, 30); 

       setExtent(maxWidth,/*temp_mgr_Height + 25*/ 70); 
      }; 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.setFont(Global.arialFont_Bold_16); 
       graphics.drawText("Start Date & Time", 10, 5); 


       graphics.drawRect(9, 25, 141, 30); 

       graphics.drawRect((Global.Display_Width - 151), 25, 141, 30); 

       graphics.drawRect(5, 1, getWidth()-10, getHeight()-2); 
       super.paint(graphics); 
      } 

     }; 

     startDateNTimeManager.add(_startDateLabelField); 
     startDateNTimeManager.add(_startTimeLabelField); 


     /** 
     * End Date & Time 
     * */ 
     _endDateLabelField = new LabelField("") 
     { 

      protected void layout(int width, int height) { 
       super.layout(150, 25); 
       super.setExtent(150, 25); 
      } 

      public boolean isFocusable() { 
       return true; 
      } 

     }; 



     _endTimeLabelField = new LabelField("") 
     { 

      protected void layout(int width, int height) { 
       super.layout(150, 25); 
       super.setExtent(150, 25); 
      } 

      public boolean isFocusable() { 
       // TODO Auto-generated method stub 
       return true; 
      } 


     }; 

     _startDateLabelField.setFont(Global.arialFont_Plain_18); 
     _startTimeLabelField.setFont(Global.arialFont_Plain_18); 
     _endDateLabelField.setFont(Global.arialFont_Plain_18); 
     _endTimeLabelField.setFont(Global.arialFont_Plain_18); 


     HorizontalFieldManager endDateNTimeManager = new HorizontalFieldManager() 
     { 

      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70); 
       Field f = getField(0); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 

       setPositionChild(f, 20, 30); 
       temp_mgr_Height = getPreferredHeightOfChild(f) +20; 

       f = getField(1); 
       layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f)); 
       //setPositionChild(f, Global.Display_Width -70, 25); 
       setPositionChild(f, Global.Display_Width -120, 30); 

       setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70); 
      }; 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.setFont(Global.arialFont_Bold_16); 
       graphics.drawText("End Date & Time", 10, 5); 


       graphics.drawRect(9, 25, 141, 30); 

       graphics.drawRect((Global.Display_Width - 151), 25, 141, 30); 

       graphics.drawRect(5, 1, getWidth()-10, getHeight()-2); 
       super.paint(graphics); 
      } 

     }; 

     endDateNTimeManager.add(_endDateLabelField); 
     endDateNTimeManager.add(_endTimeLabelField); 



     /** 
     * Add Components to Screen 
     * */ 
     LabelField searchByLocation = new LabelField("Search by Location") 
     { 
      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       super.paint(graphics); 
      } 
     }; 
     searchByLocation.setFont(Global.arialFont_Bold_18); 


     insertSearchModeManager(); 
     _workSpace.add(hfm_0); 

     searchByLocation.setMargin(5, 5, 5, 10); 
     _workSpace.add(searchByLocation); 

     _workSpace.add(hfm_1); 
     _workSpace.add(hfm_2); 
     _workSpace.add(hfm_3); 


     LabelField selectStartDateHeader = new LabelField("Select start date & end dates to check incidents in the future"); 
     selectStartDateHeader.setFont(Global.arialFont_Bold_16); 

     selectStartDateHeader.setMargin(5, 5, 5, 10); 
     _workSpace.add(selectStartDateHeader); 


     insertDateSelectionManager(); 

     startDateNTimeManager.setMargin(10, 0, 10, 0); 
     _workSpace.add(startDateNTimeManager); 
     _workSpace.add(endDateNTimeManager); 


     ButtonField btn_go = new ButtonField("Go" ,FIELD_HCENTER) 
     { 
      protected boolean navigationClick(int status, int time) { 
       fieldChangeNotify(1); 
       return true; 
      } 
     }; 

     btn_go.setMargin(10, 0, 0, 10); 
     _workSpace.add(btn_go); 


//  add(_workSpace); 

     btn_go.setChangeListener(new FieldChangeListener() 
     { 
      public void fieldChanged(Field field, int context) 
      { 
       invokeAISearch(); 
      } 
     }); 


     /** 
     * Status Manager 
     * */ 
     insertStatusManager(); 


     /** 
     * Very First time r1 = All days should be selected 
     * */ 
     /*r1.setSelected(true); 
     invokeDays_Calculatio();*/ 
    } 



    protected void invokeAISearch() 
    { } 


    private String getAllDates() 
    { 
     String dateString = Global.EMPTY; 

     return dateString; 
    } 



    private String getStartDateTime() 
    { 
     String startDateString = Global.EMPTY; 
     return startDateString; 
    } 

    private String getEndDateTime() { 
     String endDateString = Global.EMPTY; 
     return endDateString; 
    } 



    private String getSeverity() { 

     String sevString = Global.EMPTY; 
     return sevString; 
    } 




    private void show_AI(final Vector v_temp) 
    { 
    } 



    private void insertSearchModeManager() { 

     ch1 = new CheckboxField("Severe", true) 
     { 
      protected void layout(int width, int height) { 
       super.layout(getPreferredWidth(), height); 
       super.setExtent(getPreferredWidth(), height); 
      } 
     }; 
     ch2 = new CheckboxField("Moderate", true) 
     { 
      protected void layout(int width, int height) { 
       super.layout(getPreferredWidth(), height); 
       super.setExtent(getPreferredWidth(), height); 
      } 
     }; 
     ch3 = new CheckboxField("Slight", true) 
     { 
      protected void layout(int width, int height) { 
       super.layout(getPreferredWidth(), height); 
       super.setExtent(getPreferredWidth(), height); 
      } 
     }; 

     ch1.setFont(Global.arialFont_Plain_16); 
     ch2.setFont(Global.arialFont_Plain_16); 
     ch3.setFont(Global.arialFont_Plain_16); 


     HorizontalFieldManager dateSelectionManager = new HorizontalFieldManager() 
     { 
      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.sublayout(maxWidth, maxHeight); 

       setExtent(360, 50); 
      } 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.drawRect(5, 0, getWidth()-10, getHeight()); 
       super.paint(graphics); 
      } 
     }; 

     ch1.setMargin(0, 0, 0, 10); 
     ch2.setMargin(0, 0, 0, 20); 
     ch3.setMargin(0, 0, 0, 20); 

     dateSelectionManager.add(ch1); 
     dateSelectionManager.add(ch2); 
     dateSelectionManager.add(ch3); 

     LabelField selectStartDateHeader = new LabelField("Search by Severity"); 
     selectStartDateHeader.setFont(Global.arialFont_Bold_16); 

     selectStartDateHeader.setMargin(5, 5, 5, 10); 
     _workSpace.add(selectStartDateHeader); 
     _workSpace.add(dateSelectionManager); 



    } 



    private void insertDateSelectionManager() 
    { 

     r1 = new CheckboxField("All Dates" , true) 
     { 
      protected void layout(int width, int height) { 
       super.layout(getPreferredWidth(), height); 
      } 
     }; 

     r2 = new CheckboxField("Tomorrow",false) 
     { 
      protected void layout(int width, int height) { 
       super.layout(getPreferredWidth(), height); 
      } 
     }; 
     r3 = new CheckboxField("Next 7 days",false) 
     { 
      protected void layout(int width, int height) { 
       super.layout(getPreferredWidth(), height); 
      } 
     }; 


     HorizontalFieldManager dateSelectionManager = new HorizontalFieldManager() 
     { 
      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.sublayout(Global.Display_Width, 50); 

       setExtent(Global.Display_Width, 50); 
      } 

      protected void paint(Graphics graphics) 
      { 
       graphics.setColor(Color.BLACK); 
       graphics.drawRect(5, 0, getWidth()-10, getHeight()); 
       super.paint(graphics); 
      } 
     }; 


     r1.setFont(Global.arialFont_Plain_16); 
     r2.setFont(Global.arialFont_Plain_16); 
     r3.setFont(Global.arialFont_Plain_16); 

     r1.setMargin(0, 0, 0, 20); 
     r2.setMargin(0, 0, 0, 20); 
     r3.setMargin(0, 0, 0, 20); 

     dateSelectionManager.add(r1); 
     dateSelectionManager.add(r2); 
     dateSelectionManager.add(r3); 



     add(dateSelectionManager); 


     r1.setChangeListener(new FieldChangeListener() 
     { 
      public void fieldChanged(Field field, int context) 
      { 
       if (nonProgrammaticChange(context)) 
       { 
        invokeDays_Calculation(r1); 
       } 
      } 
     }); 


     r2.setChangeListener(new FieldChangeListener() 
     { 
      public void fieldChanged(Field field, int context) 
      { 
       if (nonProgrammaticChange(context)) 
       { 
        invokeDays_Calculation(r2); 
       } 
      } 
     }); 

     r3.setChangeListener(new FieldChangeListener() 
     { 
      public void fieldChanged(Field field, int context) 
      { 
       if (nonProgrammaticChange(context)) 
       { 
        invokeDays_Calculation(r3); 
       } 
      } 
     }); 
    } 


    private boolean nonProgrammaticChange (int context) { 
     return (context & FieldChangeListener.PROGRAMMATIC) != FieldChangeListener.PROGRAMMATIC; 
    } 

    protected void invokeDays_Calculation(CheckboxField selectedField) 
    { 
     r1.setChecked(false); 
     r2.setChecked(false); 
     r3.setChecked(false); 

     if(selectedField.equals(r1)) 
     { 
      togle_r1 = !togle_r1; 

      if(togle_r1) 
      { 
       r1.setChecked(true); 

       togle_r2 = false; 
       togle_r3 = false; 

       _startDateLabelField.setText(""); 
       _startTimeLabelField.setText(""); 
       _endDateLabelField.setText(""); 
       _endTimeLabelField.setText(""); 
      } 
      else 
      { 
       if(!togle_r1 && !togle_r2 && !togle_r3) 
       { 
        Calendar todaysDate = Calendar.getInstance(); 
        int tDayStr = todaysDate.get(Calendar.DATE); 
        int tMonStr = todaysDate.get(Calendar.MONTH); 
        int tYearStr = todaysDate.get(Calendar.YEAR); 


        /** 
        * In Calendar class Month start form 0 thats why I incremented one time 
        * */ 
        ++tMonStr; 

        /*System.out.println("t Date "+tDayStr); 
        System.out.println("t Month "+tMonStr); 
        System.out.println("t Year "+tYearStr);*/ 

        String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr; 

        _startDateLabelField.setText(startDateStr); 
        _startTimeLabelField.setText("00:00"); 
        _endDateLabelField.setText(startDateStr); 
        _endTimeLabelField.setText("23:59"); 

       } 
      } 
     } 

     if(selectedField.equals(r2)) 
     { 
      togle_r2 = !togle_r2; 

      if(togle_r2) 
      { 

       r2.setChecked(true); 

       togle_r1 = false; 
       togle_r3 = false; 

       Calendar todaysDate = Calendar.getInstance(); 
       int tDayStr = todaysDate.get(Calendar.DATE); 
       int tMonStr = todaysDate.get(Calendar.MONTH); 
       int tYearStr = todaysDate.get(Calendar.YEAR); 


       ++tDayStr; 
       /** 
       * In Calendar class Month start form 0 thats why I incremented one time 
       * */ 
       ++tMonStr; 

       /*System.out.println("t Date "+tDayStr); 
       System.out.println("t Month "+tMonStr); 
       System.out.println("t Year "+tYearStr);*/ 

       String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr; 

       _startDateLabelField.setText(startDateStr); 
       _startTimeLabelField.setText("00:00"); 
       _endDateLabelField.setText(startDateStr); 
       _endTimeLabelField.setText("23:59"); 
      } 
     } 


     if(selectedField.equals(r3)) 
     { 
      togle_r3 = !togle_r3; 

      if(togle_r3) 
      { 
       r3.setChecked(true); 

       togle_r1 = false; 
       togle_r2 = false; 

       Calendar todaysDate = Calendar.getInstance(); 
       int tDayStr = todaysDate.get(Calendar.DATE); 
       int tMonStr = todaysDate.get(Calendar.MONTH); 
       int tYearStr = todaysDate.get(Calendar.YEAR); 



       /** 
       * In Calendar class Month start form 0 thats why I incremented one time 
       * */ 
       ++tMonStr; 

       /*System.out.println("t Date "+tDayStr); 
       System.out.println("t Month "+tMonStr); 
       System.out.println("t Year "+tYearStr);*/ 

       String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr; 

       _startDateLabelField.setText(startDateStr); 
       _startTimeLabelField.setText("00:00"); 

       tDayStr += 7; 
       startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr; 

       _endDateLabelField.setText(startDateStr); 
       _endTimeLabelField.setText("23:59"); 
      } 
     } 

    } 


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

    } 


    protected void street_Invoke() 
    { 
    } 

    protected void postCode_Invoke() { 


    } 

    void showStreetPopUp(final String[] street_Array) 
    { 

    } 

    public void showCarParkingStreetPopUp(final String[] postCode_Array) 
    { 
    } 

    public void updateStreetField(String strVal) 
    { 


    } 

    public void updatePostField(String strVal) { 


    } 


    public boolean onClose() 
    { 
     setDirty(false); 
     return super.onClose(); 
    } 

    protected void sublayout(int width, int height) 
    { 
     super.sublayout(Global.Display_Width, Global.Display_Height + 100); 
     super.setExtent(Global.Display_Width, Global.Display_Height + 100); 
    } 

    protected void paint(Graphics graphics) 
    { 
     // TODO Auto-generated method stub 
     super.paint(graphics); 
    } 


} 

注:該代碼是在5.0的操作系統工作正常,但在6.0 & 7.0它創造的問題。 請讓我知道爲什麼我得到這個問題。

+0

請訪問[本站](http://sscce.org/)。絕對沒有必要在這裏發佈這麼多的代碼。 – Nate 2013-04-11 09:53:28

+0

hello @Nate ..我會照顧,你能告訴我爲什麼我的屏幕得到減少後,每次點擊dateSelection管理器,在insertDateSelectionManager()方法,當我評論setchangelistenr它工作正常.. – 2013-04-11 10:56:23

回答

1

問題在於,您已經針對OS 5.0上的某個特定設備制定了特定的應用程序,該應用程序顯然沒有觸摸。現在在觸控設備上,按鈕和複選框的尺寸要大得多,而您試圖將它們限制爲更小的尺寸。所以複選框通常會採取你已經完成的任何事情,但是當它們集中時,它們會嘗試爲自己騰出空間,這會干擾你的屏幕布局。刪除複選框中的人工約束,您的直接問題可能會得到解決。

但是,此代碼中存在很多問題,可能會在稍後引發問題。

  1. 使用Screen.USE_ALL_HEIGHT不會佔用整個顯示屏。

  2. 您不必要地覆蓋每個領域,以某種方式限制他們的身高。你做錯了。例如,在iaDescriptionEditField中,您已爲佈局給出了完整寬度,但隨後限制了其大小。這將導致該字段在末尾處未被繪製。

  3. 你硬編碼的寬度和高度 - 包括以像素爲單位的字體,這將使你的應用程序看起來很糟糕的高像素密度的設備,如大膽3.

  4. 要覆蓋一個Horizo​​ntalFieldManager然後完全重建子佈局方法。最好只擴展Manager類,因爲您似乎沒有使用任何Horizo​​ntalFieldManager工具。

  5. 請記住,並非所有字段都會給出正確的getPreferredWidth/Height,並且您應該只使用這些方法在佈局期間進行估計。

我建議您在考慮到需要定位的不同設備後重新考慮並重新編寫整個代碼。使用基於點的字體和測量,而不是基於像素的測量。

一切順利。

+0

@adwin感謝您的答覆據我所知,罪魁禍首部分是r1,r2,r3 setchangelistener部分..當我評論代碼時屏幕可能不會減少,並且每件事情都可以正常工作,但根據應用程序的要求,一次只能選擇一個複選框..我必須禁用其他 – 2013-04-12 05:55:21

+0

如果我不使用nonProgrammaticChange()..然後我得到堆棧溢出異常..有沒有其他方法來解決問題 – 2013-04-12 08:51:36

+0

@Mario你的setChangeListeners做了很多事情包括檢查/取消選中和設置標籤字段。試着通過評論來找出代碼的哪個部分正在做這件事。 – adwiv 2013-04-12 09:48:56