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: 638
Registered: ‎07-02-2009
My Device: Not Specified

EditField + navigationclick

Hi all,

 

am working on OS5.0. i need to do create two editfields which accepts input. after the two editfields are entered then next button should appear on the screen.

 

1) by default the editfields show "ENTER EMAIL", when user clicks on them it should disappear and allows user to input data.

2) so i need to do a validation whether the two fields are entered or not.?

 

am using navigationClick to capture teh event on the editfield and performing validation for teh fields.the followingis the code for my editField. 

class CustomEditField extends EditField 
{
	private String  _text;
	private int width=0;
	private int height=0;
	CustomEditField()
	{
		super(EditField.NO_LEARNING | EditField.NO_NEWLINE | BasicEditField.FILTER_EMAIL);
		this.setFilter(new EmailAddressTextFilter());
 	}
	CustomEditField(String label)
	{
		this();
		_text = label;
	}
	CustomEditField(String label, int width, int height)
	{
		this(label);
		this.width =  width;
		this.height = height;
	}
	public int getPreferredWidth()
	{
		if( width == 0)
			return this.getFont().getAdvance(_text);
		else
			return this.width;
	}
	public int getPreferredHeight()
	{
		if( height == 0)
			return super.getHeight();
		else
			return this.height;
	}
	public void paint(Graphics g)
	{
		  g.setColor(Color.RED);
          g.drawRoundRect(0,0,this.getPreferredWidth(),40, 10, 10);
          g.setColor(Color.BLACK);
          super.paint(g);
	}
	public  void layout(int width, int height)
	{
        super.layout(this.width, this.height);
        setExtent(360,25);
	}
	protected boolean keyChar(char ch, int status, int time)
	{
		if( this.getText().trim().equalsIgnoreCase("EMAIL ADDRESS"))
			this.clear(0);
		switch(ch)
		{
			case Characters.ENTER:	this.clear(0);
									return true;
			case Characters.BACKSPACE: 
									return true;
			default:
									return true;
		}
	}
	 protected boolean navigationClick(int status, int time)
	 {
			super.navigationClick(status, time);
			 if( this.getText().trim().equalsIgnoreCase("EMAIL ADDRESS"))
				 this.clear(0);
		  return true;
	 }
}

 

 

 

 

 

 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: EditField + navigationclick

any  help!!!!!

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 81
Registered: ‎01-28-2009
My Device: Not Specified

Re: EditField + navigationclick

 

Use method

 

textfield.setText(""); this will clear text in edit field

 

When you are developing app for touch screen always override touchEvents. Its good practice

Don't forget to mark your post as solved if you got answer. And give kudos.
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: EditField + navigationclick

You have two different requirements here:

 

1) Having a default text of "EMAIL ADDRESS" which is cleared when the user puts data in the Field

 

2) Adding a Next button when the input Field contain valid data.

 

I think you should do this processing in a different way to that which you are trying:

 

1) Do this with onFocus and onUnfocus().  When the Field is focused, if it contains "EMAIL ADDRESS", then remove this using setText("");  When onUnfocus is called, if the Field contains nothing, put back the default Text.

 

2) Use a FieldChangeListener to listen for changes to the two Field.  If the two Fields contain data, and you have not already done so, then add the Next button.  If either of the two Fields do not contain data, or contain their default text, and the Next button is displayed, then remove it.

 

This process will work correctly in both Touch and non Touch devices.  There is no need to listen for Touch Events or override touch methods.  .