2013-05-17 3 views
1
private void buildUI() throws Exception { 
     try { 
      Display.init(this); 
    countryLabel = new Label(resources.getString("Label10")); 
      countryLabel.setSelectedStyle(DefaultLayout.labelStyle()); 
      countryLabel.setPressedStyle(DefaultLayout.labelStyle()); 
      countryLabel.setUnselectedStyle(DefaultLayout.labelStyle()); 
country = new ComboBox(countryChoiceDesc);    
      country.setSelectedStyle(DefaultLayout.comboBoxPressedStyle()); 
      country.setUnselectedStyle(DefaultLayout.comboBoxNormalStyle()); 
      country.setPressedStyle(DefaultLayout.comboBoxPressedStyle());   
      CountryListener countryListener = new CountryListener(); 
      country.addSelectionListener(countryListener);  
    townLabel = new Label(resources.getString("Label12")); 
      townLabel.setSelectedStyle(DefaultLayout.labelStyle()); 
      townLabel.setPressedStyle(DefaultLayout.labelStyle()); 
      townLabel.setUnselectedStyle(DefaultLayout.labelStyle()); 
//   townList = new List(townChoiceDesc); 
//   townModel = townList.getModel(); 
//   
//   town = new ComboBox(townModel); 
      town = new ComboBox(townChoiceDesc); 
      town.setSelectedStyle(DefaultLayout.comboBoxPressedStyle()); 
      town.setUnselectedStyle(DefaultLayout.comboBoxNormalStyle()); 
      town.setPressedStyle(DefaultLayout.comboBoxPressedStyle()); 
      townListener townListener = new townListener(); 
      town.addSelectionListener(townListener); 

      districtLabel = new Label(resources.getString("Label13")); 
      districtLabel.setSelectedStyle(DefaultLayout.labelStyle()); 
      districtLabel.setPressedStyle(DefaultLayout.labelStyle()); 
      districtLabel.setUnselectedStyle(DefaultLayout.labelStyle()); 
//   districtList = new List(districtChoiceDesc); 
//   districtModel = districtList.getModel();    
//   district = new ComboBox(districtModel); 

      district = new ComboBox(districtChoiceDesc); 
      district.setSelectedStyle(DefaultLayout.comboBoxPressedStyle()); 
      district.setUnselectedStyle(DefaultLayout.comboBoxNormalStyle()); 
      district.setPressedStyle(DefaultLayout.comboBoxPressedStyle());  

      cityLabel = new Label(resources.getString("Label11")); 
      cityLabel.setSelectedStyle(DefaultLayout.labelStyle()); 
      cityLabel.setPressedStyle(DefaultLayout.labelStyle()); 
      cityLabel.setUnselectedStyle(DefaultLayout.labelStyle()); 
}catch (Exception e) { 
      System.out.println("build ui"+e.getMessage()); 
      dialog = DefaultLayout.validation(AppConstants.exceptionMsg); 
      dialog.show(); 
     } 
    } 
class CountryListener implements SelectionListener { 
     public void selectionChanged(int arg0, int arg1) { 
      try { 
//    Dialog.show("Beno","country action", "Ok", null); 
       countryValue = countryChoice[country.getSelectedIndex()]; 
       getCity(countryValue); 
       System.out.println("cityChoiceDesc.length :"+cityChoiceDesc.length); 
       if (cityChoiceDesc.length > 0) { 
//     System.out.println("city set"); 
        cityList = new List(cityChoiceDesc);  

        ListModel cityModel = cityList.getModel(); 
        city.setModel(cityModel); 

       } 
        else { 
        String citylist[] = {}; 
        List list = new List(citylist); 
        ListModel citylistModel = list.getModel(); 
        city.setModel(citylistModel); 
        String townlist[] = {}; 
        List list1 = new List(townlist); 
        ListModel townlistModel = list1.getModel(); 
        town.setModel(townlistModel); 
        String districtlist[] = {}; 
        List list2 = new List(districtlist); 
        ListModel districtlistModel = list2.getModel(); 
        district.setModel(districtlistModel); 
       } 

      } catch (Exception e) { 
       try { 
        dialog = DefaultLayout.validation(AppConstants.exceptionMsg); 
       } catch (Exception e1) { 
        // TODO Auto-generated catch block 
        e1.printStackTrace(); 
       } 
       dialog.show(); 
      } 
     } 
    } 

    class CityListener implements SelectionListener { 
     public void selectionChanged(int arg0, int arg1) { 
      try { 

       cityValue = cityChoice[city.getSelectedIndex()]; 
//    city.setSelectedIndex(city.getSelectedIndex()); 
       getTown(cityValue); 
       if (townChoiceDesc.length > 0) { 
        List list = new List(townChoiceDesc); 
        ListModel listModel = list.getModel(); 
        town.setModel(listModel); 
       } else { 
        String townlist[] = {}; 
        List list1 = new List(townlist); 
        ListModel townlistModel = list1.getModel(); 
        town.setModel(townlistModel); 
        String districtlist[] = {}; 
        List list2 = new List(districtlist); 
        ListModel districtlistModel = list2.getModel(); 
        district.setModel(districtlistModel); 
       } 
      } catch (Exception e) { 
       try { 
        dialog = DefaultLayout.validation(AppConstants.exceptionMsg); 
       } catch (Exception e1) { 
        // TODO Auto-generated catch block 
        e1.printStackTrace(); 
       } 
       dialog.show(); 
      } 
     } 
class townListener implements SelectionListener { 
     public void selectionChanged(int arg0, int arg1) { 
      System.out.println("town list"); 
      townValue = townChoice[town.getSelectedIndex()]; 
      try { 
       getDistrict(townValue); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      if (districtChoiceDesc.length > 0) { 
       List list = new List(districtChoiceDesc); 
       ListModel listModel = list.getModel(); 
       district.setModel(listModel); 
      } else { 
       String districtlist[] = {}; 
       List list2 = new List(districtlist); 
       ListModel districtlistModel = list2.getModel(); 
       district.setModel(districtlistModel); 
      } 

     } 
    } 

도시 청취자를 호출하지만 도시 청취자는 호출하지 않았지만 해당 값은 도시에서 업데이트됩니다. 도시 콤보를 선택하는 동안 그것이 왜 나를 도와 주는지 청취자라고 부르지 않습니다. 도시 콤보 상자에서 값을 선택해도 선택된 항목이 표시되지 않습니다.은 리스너를 사용하여 종속 콤보 상자를 구현합니다.

답변

1

선택 리스너가 아닌 콤보 상자와 함께 동작 수신기를 사용해야합니다. 새 목록을 만드는 대신 기존 목록에서 setModel()을 사용하면됩니다.

관련 문제