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: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer

Please help with EditField?

Hello everyone!

 

I'm try to make a searching. when i type in EditField i will display the result from a string

ex: if i type "g" it will display something like good, golf...

 

i do like this

 

EditField search= new EditField("Search : ", '');
search.setChangeListener(new FieldChangeListener() {

          public void fieldChanged(Field field, int context) {
                        // my code search

          }

 });

 

But when i debug i see when i type char on EditField, the fieldChanged function seem run manytimes, so how can control how many times the method  run?

 

Thanks in advane

 

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Please help with EditField?

When u press any Key then this Method Automatically called up according to ur code.

 

U can put the Conditions in fieldChanged Method.

-----------------------------------------------------------------------------------

Press Kudoes If Got Solution and press Accept as Solution Button.

Contributor
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer

Re: Please help with EditField?

Thanks you for you answer. can you tell more detail

 

Here is my code. i just display a simple things

 

    String [] str = {"good","bad","black","great","nice","blue","back"};

    EditField e = new EditField("Search:","");
        e.setChangeListener(new FieldChangeListener() {
           
            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                
                String text = e.getText();
                Vector v = new Vector();
                
                if(!text.equals("")){
                    
                    for(int i =0;i<a.length;i++){
                        if(contains(a[i], text)==true){
                            v.addElement(a[i]);
                        }
                    }
        
                    for(int i=0;i<v.size();i++){
                        add(new RichTextField("vector: " + v.elementAt(i))); // just display it on screen
                    }
                  
                }
                
            }
            
        });
        add(e);

 

Thanks

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Please help with EditField?

UR All String are in the String array that is str

 

And U r not using str anywhere.

Contributor
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer

Re: Please help with EditField?

what you mean?

 

when i type in EditField like "g" i want to search the g char in this string

 

String []a = {"good","bad","black","great","nice","blue","back"};

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Please help with EditField?

I think Yes,

 

If no, then tell me one thing that,

When U press Like 'g'

Then where U want to search the word which is related to the pressed character.

 

Contributor
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer

Re: Please help with EditField?

i have a function to check the 'g' character in my array string. but what i need is when i press in EditField i want to control how manytime the function FieldChanged call. because when i press the 'g' character on screen it display like this

 

good

great

-------------------

good

great

------------------

good

great

-----------------

.....

 

what i need is just display one time

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Please help with EditField?

Put all the code of field Change Method in condition

 and use a Counter. when the counter value is o then enter init. and increment that counter.

next time the counter value is 1 then the code will not run.Ok.

 

-----------------------------------------------------------------------------------------------------

I f got  the Solution then Press Kudoes Button. and Press Accept as Solution Button.

 

 

Contributor
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer

Re: Please help with EditField?

Thank you for you answer

 

so i will do like this

 

private int count=0;

public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
            
                if(count==0){
                    // do something about search
                    
                    count++;

               }

 

              // can not set count=0 here

}

 

But i when i set the counter value is 0 again for next time.( i mean the next  press)

 

thanks in advance

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Please help with EditField?

Then U have to set that Conter again on Zero on the KeyEvent.

 

-----------------------------------------------------------------------------------------------------

I f got  the Solution then Press Kudoes Button. and Press Accept as Solution Button.