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
Trusted Contributor
Posts: 144
Registered: ‎05-04-2011
My Device: blackberry mobiles
My Carrier: app development

settext issues in one line text field

Hello Friends,

 

           In my application we created four one line text fields for getting input from user. we programmatically change the text using set text. The text to be set is getting send to the one line text field without issues. But the editfield .settext works only for the first object.Can anyone help me to solve this issue.It's urgent.

Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: settext issues in one line text field

Are you using the common variable to setText, which is pointing to one object only? Please add some code snippet.
Trusted Contributor
Posts: 144
Registered: ‎05-04-2011
My Device: blackberry mobiles
My Carrier: app development

Re: settext issues in one line text field

swap_chau,

 

Thanks for ur reply,

 

This is my code

 

public static OneLineTextField wordtxt = null;

public static OneLineTextField typetxt = null;

int focus=1;

 

 in my constructor i created two one line text fields


            wordtxt= new OneLineTextField("Word*","",230,28,100,40,Field.EDITABLE,1);
            wordtxt.setFont(Utility.getInstance().getGujaratiFont("rekha", 5));
            wordtxt.setPadding(new XYEdges(0, 0, 0, 40));
            add(wordtxt);

 

            typetxt= new OneLineTextField("Word*","",230,28,100,40,Field.EDITABLE,1);

            typetxt.setFont(Utility.getInstance().getGujaratiFont("rekha", 5));
            typetxt.setPadding(new XYEdges(0, 0, 0, 40));

            add(typetxt);

 

public void setText(String text) {
        if(focus == 1){
            wordtxt.setText(text);   
        }
        if(focus == 2){
            typetxt.setText(text);  
        }
        
        
    }

    public String getText() {
        
        
        if(focus == 1){
            //text=MyAppKeyListener.TextGuj;
        text=wordtxt.getText();
        }
        if(focus == 2){
            //text=MyAppKeyListener.TextGuj;
        text=typetxt.getText();
        }
        return text;
    }
   
onelinetextfield:



import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class OneLineTextField extends HorizontalFieldManager
{
    
BasicEditField _editField;
Font headFont,headFont1;

private final static Border BORDER = BorderFactory.createRoundedBorder(new XYEdges(4,4,4,4), 0x00608820, Border.STYLE_SOLID);
private final static Border BORDER_FOCUSED = BorderFactory.createRoundedBorder(new XYEdges(4,4,4,4), 0x00f0b8a0, Border.STYLE_SOLID);

private final static Background BG_FOCUSED = BackgroundFactory.createSolidBackground(0x00EEEEEE);//
private final static Background BG = BackgroundFactory.createSolidBackground(0x00FFFFFF);

HorizontalFieldManager m1;
int Focus;


   public OneLineTextField(String label,String initialValue,final int fieldwidth,final int fieldheight,int rightwidth,int maxChars,long style,int focus)
   {
   super(NO_HORIZONTAL_SCROLL);
this.Focus=focus;
        m1 =new HorizontalFieldManager(HORIZONTAL_SCROLL|NO_HORIZONTAL_SCROLLBAR)
        {
           public int getPreferredWidth()
           {
            return fieldwidth;
           }
           public int getPreferredHeight()
           {
            return fieldheight;
           }
           protected void sublayout( int maxWidth, int maxHeight )
           {
           super.sublayout(getPreferredWidth(),
                         getPreferredHeight());
           setExtent(getPreferredWidth(), getPreferredHeight());
           }
        };
        
        //For setting fonts for LabelField and textbox
        
        FontFamily fontFamily = null;
        FontFamily fontFamily1 = null;
        try
          {
          fontFamily = FontFamily.forName("ArialNarrow");
          fontFamily1 = FontFamily.forName("");
          }
        catch (ClassNotFoundException e)
          {
          e.printStackTrace();
          }   
        headFont = fontFamily.getFont(FontFamily.SCALABLE_FONT | Font.BOLD,    18);
       // headFont1 = fontFamily1.getFont(Font.TAMIL_SCRIPT,25);
         
        //For Labelfield
        
       LabelField l =new LabelField(label, Field.FIELD_VCENTER);
       l.setPadding(0, rightwidth, 0, 20);
       l.setFont(headFont);
       add(l);  
 
       //For textbox
       
       _editField = new BasicEditField("",  initialValue,  maxChars,
                               style | EditField.NO_NEWLINE |
                                EditField.FOCUSABLE | EditField.EDITABLE|Field.VISUAL_STATE_NORMAL|EditField.FIELD_VCENTER|EditField.FIELD_HCENTER);
      // _editField.setFont(Utility.getInstance().getGujaratiFont("", 5));
       m1.add(_editField);
     //  m1.setFont(headFont1);
       add( m1 );

       init(initialValue);

   }

   private void init(String initialValue)
   {
    setText(initialValue);
    m1.setBorder(BORDER);
    m1.setBackground(BG);
   }

   protected void onFocus(int arg0)
   {
    super.onFocus(arg0);
    m1.setBorder(BORDER_FOCUSED);
    m1.setBackground(BG_FOCUSED);
   }

   public void onUnfocus()
   {
    super.onUnfocus();
    //ContributeWordScreen.focus=0;
    if(_editField.getTextLength()>0)
    {
        int atPosition = _editField.getText().indexOf("@");
        int atPosition1 = _editField.getText().indexOf(".");
        if(!(atPosition==-1&&atPosition1==-1))
        {
            if(!Lokkosh.Emailval(_editField.getText()))
            {
            Dialog.alert("Email Not Valid");
            //_editField.setText("");
            _editField.setFocus();
            _editField.setCursorPosition(_editField.getComposedTextEnd());
            }
            
           }
        }
    m1.setBorder(BORDER);
    m1.setBackground(BG);
    }
    
   
   public void setText(String text)
   {
       //Dialog.alert("text::"+text);
       try {
        
               _editField.setText(text);
          
        
    } catch (IllegalArgumentException e) {
        Dialog.alert("set text:Smiley Surprisedneline::EXCEPTION::"+e.getMessage());
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
   }

   public String getText()
   {
    return _editField.getText();
   }

 
}

Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: settext issues in one line text field

When you are trying to setText you are using focus check. The 'focus' is not changing the value except in class initialization. I think focus has got same value and hence causing the problem. Try debugging the application and check the value focus.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: setText issues in one line text field

I agree that debugging the setText actually being processed is the way to go here.  I suspect the most likely problem is that you are not doing this on the EventThread and you are getting an IllegalStateException.