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
New Contributor
Posts: 5
Registered: ‎08-09-2009
My Device: Not Specified

Is there any way to programatically invok blackberry "copy" menu on my menu?

[ Edited ]

Is there any way to programatically invok blackberry "copy" menu on my menu?

Thanks.

 

Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Is there any way to programatically invok blackberry "copy" menu on my menu?

you can use getText on the field and call Clipboard.put to copy its contents into the clipboard. another option would be to list the menu items you have and call the run method on the correct one.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Contributor
Posts: 5
Registered: ‎08-09-2009
My Device: Not Specified

Re: Is there any way to programatically invok blackberry "copy" menu on my menu?

 


simon_hain wrote:
you can use getText on the field and call Clipboard.put to copy its contents into the clipboard.
My Code as below:
            Screen s = UiApplication.getUiApplication().getActiveScreen();
            if(s == null){
                return null;
            }
                
            Field fld = s.getLeafFieldWithFocus();
            if (fld != null && fld.isSelectionCopyable() != false) {
                Clipboard cd = Clipboard.getClipboard();
                fld.selectionCopy(cd);                
                Dialog.alert((String) cd.get());        
                cd.put(null);
            }                 
            but I can't get anything. thanks.


 

New Contributor
Posts: 5
Registered: ‎08-09-2009
My Device: Not Specified

Re: Is there any way to programatically invok blackberry "copy" menu on my menu?

 


simon_hain wrote:
another option would be to list the menu items you have and call the run method on the correct one.

 

         i tried run "copy" menu:

            ContextMenu cm=fld.getContextMenu();
        
            MenuItem[] mis = cm.getItems();
            
            //Dialog.alert(String.valueOf(MenuItem.COPY));
            
                        
            for(int i = 0; mis != null && i< mis.length; i++){
                //Dialog.alert(String.valueOf(i));
                //Dialog.alert("ID:"+String.valueOf(mis[i].getId())+" String:"+mis[i].toString());
                if(mis[i].toString().equalsIgnoreCase("COPY")){
                    Dialog.alert("will run copy...");
                    mis[i].run();                   
                }               
            }

 

         Clipboard cd = Clipboard.getClipboard();
            
         Dialog.alert("cp:"+(String) cd.get());

 

         the first i can't get anything, but the second i get the first selection.

Highlighted
Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: Is there any way to programatically invok blackberry "copy" menu on my menu?

Hi mengfanpp,

 

I run the desired menu in following way -

 

This gives me the active screen:

 

                net.rim.device.api.ui.Screen _scr = UiApplication.getUiApplication().getActiveScreen();

 

This gives me the menu of the screen:


                net.rim.device.api.ui.component.Menu _menu = _scr.getMenu(0);


This gives me the desired menuItem, which I need to execute, I need to pass the position of this menuItem to get the item:

 

               net.rim.device.api.ui.MenuItem _menuItem = _menu.getItem( 3 );

               _menuItem.run();

 

Best Regards,

Kanak Sony

 

 

 

 

 

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro