Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Option [Save][Discard][Cancel]

Try this.

 

package com.rim.samples.device.helloworlddemo;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.system.*;
import net.rim.device.api.collection.util.*;
import net.rim.device.api.ui.decor.*;
import java.util.*;
import java.lang.String;

class HelloWorldDemo extends UiApplication
{
public static void main(String[] args)
{
HelloWorldDemo theApp = new HelloWorldDemo();
theApp.enterEventDispatcher();
}

private HelloWorldDemo()
{
pushScreen(new HelloWorldScreen());
}
}

final class HelloWorldScreen extends MainScreen
{ private Dialog diag;
HelloWorldScreen()
{
LabelField title = new LabelField("Hello World Demo" , LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);

add(new RichTextField("Hello World!" ,Field.NON_FOCUSABLE));

String icon ="help.png";
Bitmap _bitmap;
_bitmap = Bitmap.getBitmapResource(icon);

String [] choices = new String [] {"Save","Discard","Cancel"};
int[] vx= new int[]{Dialog.SAVE,Dialog.DISCARD,Dialog.CANCEL};

diag = new Dialog("Changes made?", choices, vx, vx[2], _bitmap);

//diag = new Dialog("Changes made?",choices,null,2,Bitmap.getPredefinedBitmap(Bitmap.questions));

UiApplication.getUiApplication().invokeLater(new Runnable()

{
public void run()
{
int iResponse = diag.doModal();
if(iResponse == 2)
{
// doSomething.... cancel was pressed
}
else if (iResponse == 1)
{
// do another thing --- Discard was pressed
}
else
{
// Save was pressed
}
}
});

}

public void close()
{
Dialog.alert("Goodbye!");
System.exit(0);

super.close();
}
}

 

 

Regards

Bikas 

Highlighted
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Option [Save][Discard][Cancel]

This is what I suggested before.. Networking operations, IO operations and doModals should be handled in a different thread..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group