I have five EditField objects in my BlackBerry app, each one will accept only one numeric character.
I want to change the focus from the first EditField to the second EditField when a character is entered. Note the focus from one to another EditField must go automatically and not by pressing Enter key or some other key.
You want to set a FieldChangeListener on the EditField to monitor when the contents of the field changes. Once the user has entered a single character you can move to the next field by calling Field.setFocus().
Lets assume your EditFields are added to screen one by one.
You could use next code:
editField<i>.setFieldChangeListener(this);
...
public void fieldChanged(Field field, int status) {
if (field instanceof EditField) {
EditField editField = (EditField)field;
if (field.getText().length() > 0) {//don't move focus in case of deleted text
Manager manager = field.getManager();
Field nextField = manager.getField(manager.getFieldIndex(editField) + 1);
if (nextField instanceof EditField) {
nextField.setFocus();
}
}
}
}
Related
I have two Grids (both in its own panel), and want to navigate between them using the Tab Key.
To do that I'm trying to focus the Grid inside a Panel (If Tab is pressed, the Grid should gain focus, so I can use the up/Down key to select Items).
Vaadin doesn't provide a .focus() method for Grid. Is there any solution so I can focus the Grid anyway?
Here is small example which shows working scenario with
Tab key pressed
Arrows down/up should points to a row (exactly in Valo this is presented as contour around one cell)
Space makes row selected (if Grid has enabled selection!) - row should be highlighted.
Code example:
#Theme ( ValoTheme.THEME_NAME )
public class MyUI extends UI {
public class A {
String a;
String b;
A(String a, String b) {
this.a = a;
this.b = b;
}
// getters & setters
}
#Override
protected void init ( VaadinRequest vaadinRequest )
{
Grid g = new Grid();
List<A> list = Arrays.asList(new A("a", "b"), new A("aa", "bb"),
new A("aaa", "bbb"));
BeanItemContainer<A> items = new BeanItemContainer<>(A.class, list);
g.setContainerDataSource(items);
Panel p = new Panel(g);
setContent(p);
}
}
Tested: Vaadin 7.5, Java 8, Tomcat 8.
You could try to use:
setFocusedComponent(p);
after setContent(p). This should exactly tells Vaadin to make panel focused. But you still must press tab - once or more (depending on rest of components, which you placed on screen).
But make sure:
Grid is selectable.
Maybe you should press Tab more than once.
Depending on Theme there could be different effects of getting focus (or even select state). It is also possible that you use some predefined project which has blocked grid css to make it lighter. So check if you can highlight one row by click on it.
Without more information I can't help more.
The OP write in an edit:
Solved the problem using Javascript/Jquery. Added this to my Panel that contains the Grid:
public class FileTable extends Panel
{
String id;
public FileTable(String id)
{
this.id=id;
Grid table = new Grid();
initGrid();
fileTable.setId(id);
}
public void focus()
{
JavaScript.getCurrent().execute("$(\"#"+id+" table:first td:first\").click();");
}
}
i am developing a mobile app in blackberry 7,i need to create a editable text field as shown in below figure with save and clear button.initially it has to show customized edittext field with predefined width(fixed as it should not exceed the defined layout) and height,and automatically get appended by new line if user requires to enter more characters after reaching predefined space as user keeps filling the field.
i googled, but i did not get any source which is similar to this.please help me by providing any suggestion or with samples
Blackberry fields decide their size in their layout field. I'm not entirely sure what EditField does in its layout, but I was able to get the behaviour you want by setting the extent. Every time the edit field text will wrap, layout will be triggered so that it can grow.
EditField editField = new EditField()
{
private final int MIN_HEIGHT = 200;
protected void layout(int width, int height)
{
super.layout(width, height);
if (getHeight() < MIN_HEIGHT)
{
setExtent(getWidth(), MIN_HEIGHT);
}
}
};
editField.setBorder(BorderFactory.createSimpleBorder(new XYEdges(1, 1, 1, 1)));
add(editField);
I have a manager that is handling the Touch click.
In order to have the Manager Focusable I have a Field that is acting as a Background and is focusable, This field change color when it is focused.
The problem is, I have multiple fields on this manager (which are not focusable), like LabelField, BitmapField, etc...
If the user click on one of non-focusable Field, it won't take into account the click on the Cell.
But if the user clicks between 2 non-focusable fields (and then click on the Background Field), the click is took into account and works fine...
I would need some kind of click through set to true, how would I do that ?
P.S. : I do not want to put all Field focusable, because when using the trackball it would go through every Field, I just want the Whole Manager to be selected, not elements inside.
The Manager will actually get the click events - normally it will just pass them on. But you can process them if you want. The following code demonstrates the easiest way I find to make sure I process everything as I want. Try it on a touch screen and non touchscreen phone.
VerticalFieldManager testVFM = new VerticalFieldManager(Manager.USE_ALL_WIDTH) {
protected boolean touchEvent(TouchEvent message) {
int x = message.getX( 1 );
int y = message.getY( 1 );
if( x < 0 || y < 0 || x >= getExtent().width || y >= getExtent().height ) {
// Outside the field
return false;
}
if ( message.getEvent() == TouchEvent.UNCLICK ) {
Status.show("Manager Clicked");
return true;
}
return super.touchEvent(message);
}
};
LabelField testlab = new LabelField("test", LabelField.FIELD_HCENTER);
testVFM.add(testlab);
LabelField testlab2 = new LabelField("test2", LabelField.FIELD_HCENTER);
testVFM.add(testlab2);
testVFM.add(new NullField() {
protected boolean navigationClick(int status, int time){
Status.show("NullField Clicked");
return true;
}
}); // So Manager can get focus
I have added 2 BitmapFields(left and right arrow) on one HorizontalFieldManager, but when I click anywhere on HFM, BitmapFields taking focus and shows that it is selected.
I want not to show focus anywhere until it doesn't click on BitmapFields.
Following is the code for it:
bmfBottomRight = new BitmapField(bmpBottomRightFocused, FOCUSABLE) {
protected boolean navigationClick(int status, int time) {
int fieldIndex = getCurrentFieldIndex();
if (fieldIndex < (surveyList.size() - 1))
updateIncrField(fieldIndex);
return super.navigationClick(status, time);
}
};
bmfBottomLeft.setPadding(5, 0, 5, ((Display.getWidth() - bmfBottomRight.getPreferredWidth()) >> 1) - bmfBottomRight.getPreferredWidth());
I am setting Padding for it..
Have added null fields new NullField(Field.NON_FOCUSABLE). And added two different null fields at left and right of bitmap field. SO I am able to getting the focus on bitmapfield, when only tapping on it.
Creating a Blackberry app.
Just a beginner, I have searched but couldn't find a solution for it though its common. If anyone could tell me how to show a password hint and a numeric hint for blackberry applications in Java.
Thanks in Advance!!
According to your query , you want a field that shows password hint and a numeric hint for blackberry applications ..
Well blackberry follow some different way , it will not show hint (PopUp Screen). Another way is to put some (information) Text in the [EditField][1] when EditField is empty .Here is the sample code for demonstration :-
*******************************************************
EditField _userName_edtField = new EditField()
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent(150, height);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
if(isFocus())
{
if(getTextLength() == 0)
{
setCursorPosition(0);
}
}
else
{
if(getTextLength() == 0)
{
graphics.drawText("User Name", 0, (getHeight() - getFont().getHeight()) >>1);
}
}
invalidate();
super.paint(graphics);
}
};
add(_userName_edtField);
*******************************************************
this is Just a simple EditField , you can customize the field according to your requirement if this is empty it will show "User Name" and if you enter some text the "User Name" will disappear ..
means the EditField is act like a Hint and this will help you ..!!!
[1]: http://www.blackberry.com/developers/docs/5.0.0api/index.html
Your question is too broad to get a specific answer but judging by what I believe is that you are talking about a label just above or below the text field to let user know what does the field requires. In this case you can provide a confirmation screen where user is shown the field requirement like field cannot be blank, or the field can only contain numeric values, etc.
You can store the password hint on the device database and when the user enters it wrong get the label field added on the screen displaying it as hint.
Something like this:
String storedPassword = ApplicationDAO.getStoredPassword();
if(!enteredPassword.equals(storedPassword)){
LabelField hintField = new LabelField();
hintField.setText("Your hint");
mainBody.add(hintField);
}