Quote:
Originally Posted by CELITE
Just call close()
If it still fails post the code showing how you display the screen.
|
Thanks CELITE for your concentartion, My code is as follow.
Code:
class Test extends net.rim.device.api.ui.UiApplication
{
public static void main(String[] args)
{
Test instance = new Test();
instance.enterEventDispatcher();
}
public Test()
{
pushScreen(new MyMainScreen());
}
}
Code:
class MyMainScreen extends MainScreen implements FieldChangeListener
{
ListField mainList = new ListField();
ListCallback mainCallback = new ListCallback();
ButtonField addButton;
ButtonField removeButton;
public MyMainScreen()
{
String firstField = new String("aaa");
String secondField = new String("bbb");
mainList.setCallback(mainCallback);
mainList.insert(0);
mainCallback.insert(firstField, 0);
mainList.insert(1);
mainCallback.insert(secondField, 1);
this.add(mainList);
addButton = new ButtonField("Add");
addButton.setChangeListener(this);
add(addButton);
removeButton = new ButtonField("Remove");
removeButton.setChangeListener(this);
add(removeButton);
}
public boolean onClose()
{
System.exit(0);
return true;
}
///////////////////List_elements_Listener///////////////////////////////////////
public boolean trackwheelClick( int status, int time )
{
switch(mainList.getSelectedIndex())
{
case 0:
Dialog.alert("Show contents of aaa!");
break;
case 1:
Dialog.alert("Show contents of bbb");
break;
};
return true;
}
//------------------------ListCallback class implementing ListFieldCallback
public static class ListCallback implements ListFieldCallback
{
private Vector listElements = new Vector();
public void drawListRow(ListField list, Graphics g, int index, int y, int w)
{
String text = (String)listElements.elementAt(index);
g.drawText(text, 0, y, 0, w);
}
public Object get(ListField list, int index)
{
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String p, int s)
{
return listElements.indexOf(p, s);
}
public int getPreferredWidth(ListField list)
{
return Graphics.getScreenWidth();
}
public void insert(String toInsert, int index)
{
listElements.addElement(toInsert);
}
public void erase()
{
listElements.removeAllElements();
}
}
////////////////Button Event Listener handling//////////////////////////////////
public void fieldChanged(Field field, int context)
{
if (field == addButton)
{
UiEngine ui=Ui.getUiEngine();
ui.pushGlobalScreen(new MyPopscreen("Please enter "),1,true);
}
if (field == removeButton)
{
mainList.delete(mainList.getSelectedIndex());
Dialog.inform("Selected item was removed successfully!");
}
}
}
Code:
public final class MyPopscreen extends PopupScreen implements FieldChangeListener {
ButtonField okButton;
ButtonField cancelButton;
EditField urlEditField;
public MyPopscreen(String question) {
super(new FlowFieldManager());
add(new RichTextField(question, NON_FOCUSABLE));
urlEditField=new EditField("URL:","");
add(urlEditField);
okButton = new ButtonField("Ok");
okButton.setChangeListener(this);
add(okButton);
cancelButton = new ButtonField("Cancel");
cancelButton.setChangeListener(this);
add(cancelButton);
}
public void fieldChanged(Field field, int context)
{
if (field == okButton)
{
int ind=0;
String newFeed=null;
add(new LabelField(urlEditField.getText()+" was added successfully"));
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
close();
}
});
}
if (field == cancelButton)
{
onClose();
}
}
public void paint(Graphics graphics) {
graphics.clear();
super.paint(graphics);
}
public boolean onClose() {
System.exit(0);
return true;
}
}
Best regards