SetText not working for more than the first textBox - blackberry

I am using a custom textbox field,and am trying to change the text programmatically using setText...
It's working for the first field, but not for the second field...
Could someone help me out here...the text to be set is getting sent into the custom textbox , but the edit field.settext works only for the first instance of the textbox...
I can't post the code right now, but will try to give a better understanding-
I have 4 text boxes in one page,with a key listener added to the page.( this is to facilitate transliteration-English to Gujarati )
I added a int value to keep track of which field has focus, and used that to call set text method on the appropriate field.
The correct method gets called, with the correct value, and still only the first text box field's value gets reset...I used debug to follow the flow, right upto the point where the edit field.setText gets executed.
I tried the same with simple edit fields instead of custom fields, and got the same result...
The setText gets executed properly when the keylistener is not active though...
So I am stumped as to what is causing the problem.
Will add the keylistener code and any other relevant code by the day end.

Please try following code:
import net.rim.device.api.ui.component.TextField;
import net.rim.device.api.ui.container.MainScreen;
public final class MyScreen extends MainScreen
{
TextField tempTextBox;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
tempTextBox = new TextField("Titile: ", "Fitst Detail");
this.add(tempTextBox);
tempTextBox.setText("Second text");
tempTextBox.setText("Third Text");
}
}
if not refresh screen then you can set
invalidate();
after serText method.
hope help full.

well, with the death of blackberry, this is not really going to help anyone, but at the same time , this question has been open for 2 years, so i decided to close it :-)
We solved the issue by having separate keylisteners for each textbox. Thank you for the assistance. –

Related

Kivy search box with suggestion?

I am beginner to kivy so seniors pls help me how we can bind textinput box to suggestion so that user and touch and select the suggestions?so user can touch(suggestion) ,select and open(suggestion)in Label.I have a long multi text file so i want to open it by chapter or by title.thanks a million for your helpgetting suggestion from search bar
opening suggestion keyword(text)to new screen/Label
it is easier to understand your questions, when you write it more specific and adding the code, e.g. of the TextInput etc.
However, if you want suggestions pop up while the user is typing anything into the TextInput: use the `on_text' method. it gets called when the text is changing.
e.g.
class SearchBar(TextInput):
def on_text(self, widget, value):
#value is the currently typed text
#call function that gets the suggestsions based on the typed text
# use add_widget() function to create Widgets into the layout for the suggestisons....
pass

Vaadin: force Button to be visually disabled

I have several TextField's inside a window along with a Button, e.g. aButton.
The TextField's, Button, and window all have setImmediate(True).
When a TextField loses focus some validation code is executed and if it fails it calls:
aButton.setEnabled(False);
When incorrect data is entered into one TextField and then focus is lost the debugger shows that aButton.setEnabled(False) is called but aButton still looks enabled.
Two possible things can happen from here:
1.) If one modifies data in another TextField and exits that field (loses focus), the validation can be successful or not for that field but the system knows to call aButton.setEnabled(False) as the previous TextField is still invalid. This time though aButton is visually disabled.
2.) If one clicks on aButton which is visually enabled it produces this warning then visually becomes disabled:
Warning: Ignoring variable change for disabled component < class 'ui.button.Button'>, caption=OK
Currently using Vaadin 6.7.3
Are there any known work arounds to force aButton to visually become disabled immediately (force the client to update) after manually setting it to be disabled?
Sadly I have only Vaadin 7 at my disposal right now, but I checked this anyway. It works as you wanted it to work and I have to jump to the conclusion that this should be the same in Vaadin 6.7.3. This part is not really different in Vaadin7... Have you tried this feature in an isolated code (only a textbox and the button)?
VerticalLayout vlTestContent = new VerticalLayout();
final Button butChangeMe = new Button("Enabled");
final TextField tf = new TextField("Blur", "default value");
tf.addBlurListener(new BlurListener() {
private static final long serialVersionUID = 5544993392287938660L;
#Override
public void blur(BlurEvent event) {
butChangeMe.setCaption("Disabled");
butChangeMe.setEnabled(false);
}
});
Button but = new Button("Change button", new ClickListener() {
private static final long serialVersionUID = -2235317499126190105L;
#Override
public void buttonClick(ClickEvent event) {
butChangeMe.setCaption("Enabled");
butChangeMe.setEnabled(true);
}
});
vlTestContent.addComponent(butChangeMe);
vlTestContent.addComponent(tf);
vlTestContent.addComponent(but);
(The second button is just for fun)
button.setVisible(false) will always work. You need to be careful to not fire up a another event on the focus lost event that ends up setting the visibility of the button to true.
You can request a repaint of a component or the whole window, but the whole point of the framework is that you will never need to do that, because visually modified components will automatically repaint on each request.
Just to be curious, do you let your request to finish before trying to see if the browser updates? Or you look at your browser right after you pass the setVisible() line in your debugger ?
I think that your point nr 2 happens because you clicked on the button, and what happens in this order is: 1st your focus lost event runs (which probably disables your button), 2nd button click runs and somehow a repaint is requested for that button because a state change happened in the button but a repaint show the warning that it won't do anything with it because it is disabled (was just disable by the focus lost event)
As a side note. I think this UI won't make for a good user experience, it should be the other way arround, if a validation is ok, then show the button (or better, always show the button, but enable/disable instead) But it depends...

Blackberry jumpy scroll

I am having trouble with vertical scrolling on a blackberry app.
it works just fine on touch screens, but when scrolling using a track pad, it jumps from being at the top position to being at the bottom position.
Anyone had a similar problem? any idea what i could try?
Here is a snippet from my code. i have a static background image and the fields scroll on top of it:
vertical_main = new VerticalFieldManager(USE_ALL_WIDTH |NO_VERTICAL_SCROLL |USE_ALL_HEIGHT);
vertical_AllTags=new VerticalFieldManager(USE_ALL_WIDTH | VERTICAL_SCROLL);
// i then add all the fields to vertical_AllTags
vertical_main.add(vertical_AllTags);
vertical_main.invalidate();
add(vertical_main);
thanks in advance for your help
EDIT:
The suggestion of giving each field focus was correct. the only other part that needs to be done is when you override the onFocus method for a field, you need to call the super() function so that all the other normal parts of the onFocus method are still called:
protected void onFocus(int direction) {
text_select=true;
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
text_select=false;
invalidate();
super.onUnfocus();
}
Thank you so much.
This is common issue in non touch devises for beginners.
if you want to scroll field by field there is two ways
1) you need to give the focus to all fields then it will come field by
field focus down
another way is means you dont need to focus on each and every field
2)just add the NullField after your every field and give focus to all
NullFields then your trackball will bring your screen field by field
This happends beacuse in TrackWheel Scrolling it scrolls up to the next Focused field. I think you are not give any focus between the vertical_AllTags.
You can solved this by using NullField() class. Like...
add(new NullField(Field.FOCUSABLE))
when you add add(new NullField(Field.FOCUSABLE)); you will get the null focus which is not know by you. And you can navigate all the fields like Touch Screen.
You can solve that issue by adding two vertical field manager.. take a look at the code in this post

How to access filed on the screen using Screen Object ( UiApplication.getUiApplication().getActiveScreen())

My Query is How to access Fields on the stacked screen using Screen Object ?
The exact problem is as follows:
I have one screen which has one text field (ClientName) when user clicks on that field , application will then push a new screen and it will allow the user to search in remote database using MyWebSerivces. and when user selects the one client from the search result ,i want to set the text Field on the previous screen with the text that user has selected on the current screen..
i have tried the pushScreen( new screen("text) ) and that might be the result if i want to do this operation only once but this is not the option for me since there is two more such field which will go to other screen to fetch the data from webservices . and if i every time i push new screen then after every pushscreen operation i will only get one field set with the desired text
This not a blackberry (or any specific programming language) related question. This is a question of application architecture and common sense. If one screen should change a Field of another screen, then just pass a reference of the Field to the screen that will change it.
hi i once had same problem and i did like this:
Screen1
------------------
Client Name | text field |
------------------
When user clicks on this text field or any button you push Screen2
In screen 2 when user selects a particular value then u do this.
1) take a static variable in main class say clientName.
2) set value of this variable.
3) pop active screen
UiApplication.getUiApplication().getActiveScreen();
when this code is called then u come back to Screen1
Now in screen1 a method is called
public void onExposed()
{
//here u can set the text in textfield using the static variable
invalidate(); // for repainting
}
i have found the answer to my question. the solution was there lying in my question but at first i was not able to find it.
solution was very simple
when i wrote i want to use
UiApplication.getUiApplication().getActiveScreen()
that was almost the right way and i was proceeding in right direction but the thing that i was missing was " I was not casting the screen (that i have just retrieved form the stack top ) to its type
only thing i should have done is "should have casted screen to its type.like this
UiApplication.getUiApplication().posScreen(this)
(MyScreen1) UiApplication.getUiApplication().getActiveScreen()
now i am able to access all the fields on the retrieved screen (MyScreen1)
things to keep in mind
make sure u cast the screen to its type only otherwise bb will give u resource not found error
Benifits of using screen on Stack
u can use already created screen from the stack no need to create new one
if u will create new screen it will be stacked in memory and will consume more and more memory even if its of no use ( make habit to pop the screen if it is of no use instead of leaving it on stack))
no need to create any static variable since u will be able to set all the field right away from other screen

Blackberry Maps closing oddly. Not Google maps

I'm having some trouble finding documentation on CLOSING a blackberry map.
My map opens, albeit with some odd marker behavior, but when you close the map it displays a clear screen.
The invoke code is quite simple, as the map request calls a new controller and within the constructor is this:
String document = "<location-document>... etc";
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments( MapsArguments.ARG_LOCATION_DOCUMENT, document));
I tried to add a close line
public boolean onClose() {
UiApplication.getUiApplication().popScreen(this);
return true;
}
but this is not being applied to the map itself, but the page the map opened into. That's logical, I guess.
Maybe I'm going about this all wrong. I don't know of how to open a map another way, or if there is a way to have the close button close the map AND the containing screen.
Any help is appreciated.
I solved this with a simple one line function that fixed this problem.
public void onExposed()
{
UiApplication.getUiApplication().popScreen(this);
}
Adding that to the map controller closes the map application when the user clicks the back button. Simple as that.

Resources