日期:2014-05-20  浏览次数:20709 次

2个关于菜单的小问题
Java code

package gesanri;

import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;

public class City implements CommandListener{
    private Displayable displayable;
    private Display display;
    private Form form;
    private Command back;
    private ChoiceGroup province;
    private ChoiceGroup city;
    private String[][] provinceAndCity;
    
    public City(Display display,Displayable displayable) {
        this.display = display;
        this.displayable = displayable;
        display = Display.getDisplay(MainMidlet.instance);
        provinceAndCity = new String[][]{{"直辖市","北京","上海","天津","重庆"},{"特别行政区","香港","澳门"},{"黑龙江","哈尔滨","齐齐哈尔","牡丹江","大庆","伊春","双鸭山","鹤岗","鸡西","佳木斯","七台河","黑河","绥化","大兴安岭"}};
        
        form = new Form("新增城市");
        back = new Command("返回",Command.BACK,1);
        province = new ChoiceGroup("省份:",ChoiceGroup.POPUP);
        city = new ChoiceGroup("城市:",ChoiceGroup.POPUP);
        province.append("请选择", null);

        for(int i = 0; i < provinceAndCity.length; i++)
            province.append(provinceAndCity[i][0], null);
        city.append("请选择", null);
        form.append(province);
        form.append(city);
        form.addCommand(back);
        form.setCommandListener(this);
    }

    public void show(){
        display.setCurrent(form);
    }
    
    public void commandAction(Command c, Displayable dpa) {
        if(c == back){
            display.setCurrent(displayable);
        }
    }
}



这是部分程序,我要显示城市和省份的二级联动下拉菜单,有两个小问题:
1. 我有办法让省份和城市显示在同一行吗?而不是现在的2行
2. 一进界面就能看到“请选择”3个字,但我点开后,请选择还显示在第一条,有没有办法使点开后“请选择”就看不见了,第一条就是直辖市?

------解决方案--------------------
将请选择放在一个txtbox里,选了之后就将它的内容清空!
我感觉这个不用去掉吧!