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
Contributor
Posts: 13
Registered: ‎06-17-2010
My Device: 8900
Accepted Solution

how to remove menu on button click

I have made a button aaray

Then how can I remove menu on click to next screen

Developer
Posts: 80
Registered: ‎06-06-2011
My Device: bold 9000

Re: how to remove menu on button click

Try giving ButtonField.CONSUME_CLICK and you will have to explicitly write the action for the button in fieldchanged

 

Regards

Krishnan.

Contributor
Posts: 13
Registered: ‎06-17-2010
My Device: 8900

Re: how to remove menu on button click

i am giving

ButtonField bf=(ButtonField)field;

in field change

now how i will give the consume click event?

Contributor
Posts: 29
Registered: ‎05-11-2011
My Device: ANY

Re: how to remove menu on button click

You can simply add  detect on click on the button by

 

buttonField.setChangeListener(new FieldChangeListener() {
                                public void fieldChanged(Field field, int context) {
                                //Write code here you want to execute on button click.
                                    
                                }
                            });

 

 

Sample code to modify menu

    /**
     * Method to make menu
     */
    protected void makeMenu(Menu menu, int context) {

        MenuItem viewFullScreenMenuItem = new MenuItem("View in full screen",
                0, 1) {

            public void run() {
                if (currentBitmap != null) {
                    pushFullScreenViewPrizeScreen();
                }
            }
        };
        menu.deleteAll();
        menu.add(viewFullScreenMenuItem);
    }

 

 

 

Developer
Posts: 80
Registered: ‎06-06-2011
My Device: bold 9000

Re: how to remove menu on button click

When initializing a button you will use the following statement 

 

ButtonField ok = new ButtonField("ok",ButtonField.CONSUME_CLICK)

 

when you do the above it will avoid the menu poping up. 

 

Regards

Krishnan.

Contributor
Posts: 13
Registered: ‎06-17-2010
My Device: 8900

Re: how to remove menu on button click

private

void createButton(String list,finalString folder)

{

VerticalFieldManager vfm=

newVerticalFieldManager();

String[] nameArr = SplitString.split(list,

"/");

ButtonField[] bf;

bf=

new ButtonField[nameArr.length];

 

label=folder;

vfm.deleteAll();

for( int i=0;i<nameArr.length;i++)

{

 

bf[i]=

newButtonField(nameArr[i]);

vfm.add(bf[i]);

bf[i].setChangeListener(

this);

}

add(vfm);

//FileConnection fc = (FileConnection)Connector.open("file:///SDCard/NewApp/"+folder+bf[i]);

 

}

 

 

public

void fieldChanged(Field field, intcontext)

{

try{

 

ButtonField bf=(ButtonField)field;

String lb=

"";

FileConnection fc = (FileConnection)Connector.open(

"file:///SDCard/NewApp/"+label+"/"+bf.getLabel());

Enumeration e = fc.list();

if(e.hasMoreElements())

{

while(e.hasMoreElements())

{

lb=lb+e.nextElement();

}

//

// if(lb!=null||lb.equalsIgnoreCase(""))

// {

String[] count=SplitString.split(lb,

"/");

 

MyScreen myscr=

newMyScreen(count);

UiApplication.getUiApplication().pushScreen(myscr);

// }

}

 

}

catch(Exception e) {

 

Dialog.alert(

""+e.getMessage());

e.printStackTrace();

}

 

}

 

 

how can I give Consume click in button array I am not getting??

Please refer this code 

make menu still give a Pop up which I dont want

I alredy tried that solution

Contributor
Posts: 29
Registered: ‎05-11-2011
My Device: ANY

Re: how to remove menu on button click

Write Field change listner is the loop itself

 

for( int i=0;i<nameArr.length;i++)

{

 

bf[i]=

newButtonField(nameArr[i]);

vfm.add(bf[i]);

//  bf[i].setChangeListener(this); I commented this code, replace with following

 

 

bf[i].setChangeListener(new FieldChangeListener() {
                                public void fieldChanged(Field field, int context) {
                               

//Write code here you want to execute on button click.
                                    
                                }
                            });

}

 

Do like if you found the solution

Contributor
Posts: 13
Registered: ‎06-17-2010
My Device: 8900

Re: how to remove menu on button click

my issue is that how i have to give consume click in button aaray

My code is wrking fine in both the ways

with listener inside or outside the loop

 where i have to put consume click in button array or elsewhere

Developer
Posts: 80
Registered: ‎06-06-2011
My Device: bold 9000

Re: how to remove menu on button click

Inside the button array 

Contributor
Posts: 13
Registered: ‎06-17-2010
My Device: 8900

Re: how to remove menu on button click

:smileysurprised:

where inside

can u please write that part of code

 

ButtonField[] bf;

bf=

new ButtonField[nameArr.length];

 

label=folder;

vfm.deleteAll();

for( int i=0;i<nameArr.length;i++)

{

 

bf[i]=

newButtonField(nameArr[i]);

vfm.add(bf[i]);

bf[i].setChangeListener(

this);

}

 

in thise button aaray where???