How to move the focus to the next component in Blackberry? - blackberry

Can anyone tell me how to move the focus to the next component in the screen?
I have one verticalmanager with verticalscroll. This vertical field manager consists of an edit field with approximately 100 lines of data. Below this vertical field manager I have one button. If I want to move my focus to that button it means I have to pass through all those 100 lines in that edit field.
Is there another way to pass the focus to the button directly by clicking a single button?

Based on Richard's answer and your comment, I think the correct way to set the focus on the submit button when the ESC key is pressed in the edit field is as follows:
public boolean keyChar(char key, int status, int time)
{
if (key==Characters.ESCAPE)
{
submit.setFocus();
}
return super.keyChar(key, status, time);
}
Note: The use of the ESCAPE key might not be the best option. You might want to check if a modifier key (such as Alt) is pressed by checking the status argument and set the focus in that case. You are advised to use your discernment when using this code.

You would have to extend one of the containers of the edit field, process key presses looking for the key press you select (it will have to be one not consumed by the edit field). When received call the setFocus() method on the button.

You could make the field with the 100 lines of text unfocusable. When it is unfocusable, and you scroll over it, the cursor should skip the 100 lines, and go straight to the button at the bottom.

There are options:
use navigationMove (if dx > some value) if edit field not in edit mode
use menu instead of buttons
use hotkeys
use paging in list so there will be no scrolling

Related

When typing at the end of the editmask, it will pass the number to the left side until it reaches the last one

Good afternoon,
I'm doing a project in delphi that uses editmask. I'm using the phone mask.
When clicking on edit to write the phone number, it goes to the last field on the right, so it is necessary to go back with the backspace to the beginning of the edit on the left.
i would like to find a way that when the user typed the number in the last field on the right, it was passed to the left. So on until you complete the phone field. It would be possible?
Using an example of what it would look like:
I couldn't think of a way to do it
The component is called TMaskEdit.
Just like anything that bases on TEdit putting the focus onto the control will by default put the text cursor at the end of its content
via keyboard, should .AutoSelect be FALSE and
via mouse if clicking behind any text (by default the text is aligned to the left).
You should have experienced this with the other components already. If you want the text cursor to always be at a certain position upon focusing the control, then do that in such an event handler:
for keyboard use OnEnter:
procedure TForm1.MaskEdit1Enter(Sender: TObject);
begin
(Sender as TMaskEdit).SelStart:= 1; // Second position
end;
and for mouse use OnClick with the same code.
It even works unbound to how the property .AutoSelect is set.
Using Backspace is the worst choice input wise, as it always deletes potential content and needs to be pressed several times to go to the first position. Why not using the Home key instead?

Unable use a TextField at the bottom of the screen in a LazyColumn

I have this code
setContent {
val items = mutableListOf<Int>().apply {
(1..100).forEach { add(it) }
}
LazyColumn {
items(items) { item ->
TextField("$item", {})
}
}
}
With android:windowSoftInputMode="adjustResize" in my AndroidManifest.xml.
If I click on a TextField at the top of the list, I can enter text fine.
If I click on a TextField near the bottom of the screen, the keyboard appears momentarily, then disappears quickly after, and prevents me from entering text.
How can I enter text when the TextField is at the bottom of the screen? Thanks!
Your keyboard disappears after having appeared for a brief, shiny moment. Here's the reason:
You tap the TextField, it calls it's built-in focus requestor, and requests the focus from the OS by calling appropriate (or inappropriate, who's to say) internal methods, as a result of which, the keyboard pops out (again, built-in mechanism.) and you can type all the more you want... AS LONG AS THE FIELD IS VISIBLE; or in Compose terms, long as the Composable holding the requestor, is in composition.
It should be clear, that once the Composable that owns the focus requestor goes off the screen, it is destroyed (well not every time, there are only certain specific cases when it is destroyed..., but yours is one of them), and when the Composable is destroyed, the focus requestor is destroyed. No focus requestor, no focus owner - the keyboard vanishes.
Now this is really important because you are using a LazyColumn, a lazy Composable, infamous for its merciless slaughtering of the Composables that are no longer visible to the user. HENCE, as long as it is the top (or other "visible") textfield that is in concern, it stays and works as expected. However, the bottom textfield, as the keyboard pops up, goes so much out of the visible bounds, that it gets slaughtered (recycled is the technical term, but what fun is that?), taking away the purpose of the keyboard.
Now, the lazy column, like any criminal, left a clue behind, and didn't notice it, which lead us to catch him red-handed. It is quite interesting, really, to see the column in action.
Now, workarounds include using a column, instead of a lazy column; creating your own lazy column using a custom lazy Composable, and manually handling the heap size for the Composable so the final field doesn't go out of composition.
That's it, you're cured.
Just leaving another answer, since OP didn't verify other purpose of him specifying adjustResize,if whether removing or changing it will be fine, but another solution aside from the mentioned comment about different API version is specifying adjustPan, which worked in my case, either
via AndroidManifest
android:windowSoftInputMode="adjustPan"
or programmatically
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
Same code base but with adjustPan
This issue is fixed in the current alpha version 1.4.0-alpha05
https://issuetracker.google.com/issues/179203700

How to make ios keyboard with two type of return button?

My app has a text field that accepts a number. After the user fills the number, I want my user to have two choice of return buttons. One return to run function A, and one return to run function B. They also have to hold down the return button for 2 seconds to make it work.
Does anyone know how to do this? Please answer in Swift.
Configure and add buttons to the text field's inputAccessoryView; this view, including its subviews (the buttons), will appear at the top of the keyboard.

combobox steal keyboard from main window in pyqt

I'm writing a small pyqt program. I want the main window to to react to arrow movement. I added an event to my MainGui class, keyPressEvent, that handle this. The event work fine as long as I don't press certain buttons such as Key_Up or Key_Down are directed to my (currently only) QComboBox and not to my mainGui. I tried to give the focus to mainGui after each paintEvent but then I need to double click on buttons/comboBox.
Then I tried to use the MousePressEvent to check if a certain element is under the mouse. This work fine with the comboBox, but not with the button.
So, how can I direct key events to the mainGui or give the focus to QButtons?
I used eventFilter to identify when the mouse enter the QPushButton and give it focus:
def eventFilter(self,source,event):
if event.type() == QtCore.QEvent.HoverMove:
if self.execButton.underMouse():
self.execButton.setFocus()
self.keepFocus=False
else :
self.keepFocus=True
keepFocus is a flag I initialized in the __init__ function of the class. I added this part at the paintEvent function
if self.keepFocus:
self.setFocus()
else:
self.keepFocus = True
Now, I keep the focus at the MainGui and I only give it to the button when the mouse hove over it. If I do another action (like pressing a mouse button or a keyboard key) the focus is given back to the MainGui. This will create some buggy filling (For example, I need to press twice a keyboard key before the first response) but this is workable.

Disable keyboard shortcut (delphi)

I created a form in Delphi.
Say I have a Form with a speedbutton with label "&Add" (underline A, as a keyboard shortcut), and a dbgrid (read-only state) (or other control like TButton).
Then I changed the focus to Dbgrid (dbgrid got a focus) (or to TButton).
Every time I press the a key on the dbgrid, the onClick method on the speedbutton triggers.
Sometime I need to disable it for a while for a reason, and then i enable it again.
How to disable the speedbutton shortcut?
And then how to enable it again?
The form is pressing the button when you press A because the button has expressed interest in that key, and nothing else on your form is accepting keystrokes. If you had an edit box on your form, and it had the input focus, then the button would not be triggered.
You can make a control indicate that it wants to receive keystrokes when it has the focus, but that generally happens when writing a custom control, where you have some idea of what the new control class should do when it receives keyboard input.
If you don't want the button to be triggered, you can disable it. Another option is to alter the OnClick event handler to check other conditions (such as whether the grid has focus) before performing the usual click-handling code.
You could disable the shortcut by changing the speed button's label from &Add to Add. Change it back when you need to enable the shortcut again.
Please note that specifying an accelerator character like that enables two shortcuts, one is just the key prefaced with the & and the other the same key with Alt. So, in your case they would be A and Alt+A. In the same way, eliminating the accelerator disables both shortcuts. So, keep in mind that with this method of disabling the shortcut you would be unable to trigger the button neither with A nor with Alt+A.

Resources