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);
            }

        }
    }

国を選択すると、町のリスナーが呼び出されますが、都市のリスナーは呼び出されませんでしたが、対応する値が都市で更新されます。都市のコンボを選択している間、誰かが私を助けてくれるのはなぜ町のリスナーを呼び出さないのですか。都市コンボボックスで値を選択しても、選択したアイテムが表示されません

4

1 に答える 1

1

選択リスナーではなく、コンボ ボックスでアクション リスナーを使用する必要があります。新しいリストを作成する代わりに、既存のリストで setModel() を使用します。

于 2013-06-13T11:41:34.157 に答える