如何在JAVA ME,LWUIT上创建后退按钮

时间:2013-01-23 15:01:25

标签: java java-me lwuit

我在创建后退按钮方面遇到了一些问题。现在表格中有列表,我需要在右下角的这个表格上创建按钮,当滚动列表时,按钮保留在其位置(右下角)。 我正在尝试在屏幕下方创建容器并使其隐形。但它没有帮助,因为列表不会出现在容器下。

2 个答案:

答案 0 :(得分:1)

你可以试试这个......

import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Display;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
public class FirstApp extends MIDlet implements ActionListener{

Form f;
Command exitCommand;
public FirstApp()
{
    //display form
   Display.init(this);
   f = new Form("myForm");
   f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}

public void commandAction(Command c, Displayable dis) 
{

}

protected void startApp() throws MIDletStateChangeException 
{   
   //add exit button
       Command exitCommand;
   exitCommand = new Command("EXIT")
   {
        public void actionPerformed(ActionEvent e) {
            notifyDestroyed();
       }
   };
  f.addCommand(exitCommand);
  f.setBackCommand(exitCommand);
}

答案 1 :(得分:0)

您需要在对象命令中使用。

Command cmd = new Command(searchText) {
      public void actionPerformed(ActionEvent evt) {
           //TODO - implement back 
        }
    };

而不是将他添加到表格

f.addCommand(command);