AutocompleteTextView - it almost works until I tabaway from it? - android-emulator

I have an AutoCompleteTextView control serviced by an 'OnClick' Listener. It extracts a list of items from a database and populates the array adapter attached to the control. When I enter sufficient text to isolate an entry in the adapter list (usually about 2 characters) and I select the identified item, the adapterview's 'OnItemClick' Listener is invoked and I am able to identify the selected item, set the text in the AutoCompleteTextView, and execute its performCompletion() method. When this routine completes, the virtual keyboard remains in place. When I 'Tab' away from the control I receive a NullPointerException!
Any suggestions appreciated ...
PS: this display is generated programmatically.

You can use the snippet below to hide the keyboard.
private static void hideSoftKeyboard (View view) {
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}

Related

How to select a treeItem in a treeView, after checking a Condition on that treeItem, in Javafx

I have downloaded familyTree project and it doesn't have the ability to search for an specific family member!
I have added a search button to it, and in the handler method section, I need the code that searches for a member that has the specified socialID , and select it (scroll it to the sight, and make it blue (selected)). But I don't know how to programmatically select a treeItem, and make it visible and selected?
My code:
#FXML
private void btnSearch_click(ActionEvent event){
for(TreeItem<FamilyMember> treeItem:root.getChildren()){
if(treeItem.getValue().getNationality().toString()=="22"){
// treeView.setSelectionModel(item);
treeView.getSelectionModel().select(treeItem);
//it still doesnt select the item with nationality=="22"
break;
}
}
}
You can select the item with
treeView.getSelectionModel().select(item);
and if you still need to scroll (I think selecting it might automatically scroll to it), do
treeView.scrollTo(treeView.getRow(item));
A couple of notes:
I do not understand the for loop. Why are you doing
TreeItem<FamilyMember> item = root.getChildren().get(i);
and why are you creating the index i? What is wrong with the treeItem variable you already defined in the loop syntax? Isn't this necessarily exactly the same thing as item?
You need to read How do I compare strings in Java?

Dynamically reload a table in a form programatically

I have a form in Dynamics AX which displays a table of two columns in a grid. I also have a button on the form. I am overriding the clicked method of the button to update the Address field of the table. For example, here's my X++ code:
void clicked()
{
AddressTable addr;
ttsBegin;
select forUpdate addr where addr.addressID == 1;
addr.Address = "new address";
addr.update();
ttsCommit;
super();
// reload table here
}
What I would like to do is to add a code to the clicked function which will reload (re-select) the updated records and show them in the form without a need of reopening the window or refreshing it using F5 (for example).
I went through forums and AX documentation and found a few methods like refresh and reread, but they are FormDataSource class methods and I failed to make it happen inside the clicked handler above.
So, what I really want to accomplish programaticallyis what F5 does behind the scenes when clicked on an open form.
Maybe just addressTable_ds.research(true); will do the job.
See also Refresh Issue on the form when the dialog closes.

How to add a custom selection Handler to a celltable

I want to add a special selection model to the celltable. Basically the function i want to have is to select a row on the table which is located on left side, a corresponding form will pop up on the right side.
I know so many people will use the singleSelectionModel with SelectionChangeHandler.
But there is problem with this method.
For example, if I select row 1 on the table. the form pop up. I close the form by clicking the close-button. Later then, I select the row 1 again, the event is not fired, because it is SelectionChangeHandler. I have to select other row before doing this. This is no good.
So I think there are a few ways to do this:
Make the row deselected right after I select the row.
Use click handler to fire the event ( to pop up the form)
Use other selection model with other selection handler to do this. (I have no ideas about this though)
So my questions are,
Does anyone know what kind of other selection handler I can use for this.
If I use the click handler on celltable, will there be any problem?
I just want to learn more about this. So any ideas will be welcome.
Thanks a lot.
Best Regards.
Use NoSelectionModel. It won't update the table view after the row is selected. That is, even if the same row is selected, the change event is fired.
//Here 'Contact' is the datatype of the record
final NoSelectionModel<Contact> selModel = new NoSelectionModel<Contact>();
selModel.addSelectionChangeHandler(new Handler() {
#Override
public void onSelectionChange(SelectionChangeEvent event) {
Contact clickedObject = selModel.getLastSelectedObject();
GWT.log("Selected " + clickedObject.name);
}
});
table.setSelectionModel(selModel);
I have using cell table in my each project. The better way to just deselect row manually as u mention. and make change css such as selected cell table's row look not changed after selection.

SIP prevents EF from auto-detecting object change on WP7

I have an issue trying to persist entities to the DB using code-first technique. For example of what I am doing you may look at the following MSDN Sample. The app generally works as intended except for one case.
If I have an existing entity and I bind it to a page that has a TextBox to hold the Title field and a AppBar icon to Save (similar to the 'New Task' screenshot in the above link, but with values pre-filled with existing entity with Two-Way binding), the following issue occurs. If I have the TextBox selected and I change the title and hit the save button, it updates the entity in-memory so that the full list now displays the new title. But the new title is not persisted to the DB (it does not auto-detect changes). This is weird, not just because the object in-memory has changed, but also because if I deselect the TextBox and then hit save, it will persist the changes to the DB.
I have seen other questions on SO with some change detection issues, they suggest adding this.Focus() or focusing some other element at the beginning of the save method. This does not help in my case. Unless I tap on screen to deselect the TextBox and hide the keyboard (or press Return key on the keyboard, which I bound to do this.Focus()), it won't detect the object as changed.
How can I address this? What exactly is stopping EF from detecting the object change when the keyboard is still visible?
Not sure if I follow exactly what you described but I think the problem is that the property you have bound your textbox to does not get updated until the TextChanged is fired on the textbox, and this is done first when you leave the Textbox, basically it will lose Focus if you tap somewhere else.
There is a simple workaround for this and it behaviors. By making a small behavior you can force the textbox to update the binding on each keystroke - so everything is updated while you type and keyboard is still there.
Behavior:
/// <summary>
/// Update property on every keystroke in a textbox
/// </summary>
public class UpdateTextSourceTriggerBehavior : Behavior<TextBox>
{
protected override void OnAttached()
{
this.AssociatedObject.TextChanged += OnTextBoxTextChanged;
}
void OnTextBoxTextChanged(object sender, TextChangedEventArgs e)
{
var bindingExpression = AssociatedObject.ReadLocalValue(TextBox.TextProperty) as BindingExpression;
if (bindingExpression != null)
{
bindingExpression.UpdateSource();
}
}
protected override void OnDetaching()
{
this.AssociatedObject.TextChanged -= OnTextBoxTextChanged;
}
}
Now just attach this behavior to your textbox like this:
<TextBox Text="{Binding YourPropertyName, Mode=TwoWay}">
<i:Interaction.Behaviors>
<UpdateTextSourceTriggerBehavior/>
</i:Interaction.Behaviors>
</TextBox>
This will keep the property on your viewmodel updated all the time, so that when you tap on save directly after typing in the textbox it will save the correct value. Hope it helps!
Cheers,
Anders

Change the order of event handling in GWT

I have a Suggest box which has 2 hadlers: SelectionHandler for selecting items in SuggestionList and keyDownHandler on TextBox of SuggestBox. I want to prevent default action on event(for example on Enter pressed) when the suggestion list is currently showing. The problem is that SelectionEvent is always fires before KeyDownEvent and suggestion list is closed after SuggestionEvent fired, so in KeyDownEventHandler suggestion list is already closed. And I can't use prevent default action on Enter with checking the suggestion list is showing like this:
if ((nativeCode == KeyCodes.KEY_TAB || nativeCode == KeyCodes.KEY_ENTER) && display.isSuggestionListShowing()) {
event.preventDefault();
}
where display.isSuggestionListShowing() is the method which calls isShowing on SuggestBox .
So how can i change the order of event handling(Selection before KeyDown to the keyDown before Selection) in this case?
I'm assuming you mean SuggestBox instead of SuggestionList, as there is no class by that name in the gwt-user jar.
The SuggestBox uses the keydown event to provide the SelectEvent - if it can't see the keys change (from the browser, which actually picks up the user's action), it can't provide the logical selection event.
This means that reordering events doesn't really make sense - you can't have the effect before the cause. In many cases, the browser emits events in a certain order, and there is no way to change this, so you have to think differently about the problem.
(Also worth pointing out that preventDefault() only prevents the browser from doing its default behavior - other handlers will still fire as normal.)
One option would be to preview all events before they get to the SuggestBox, and cancel the event in certain cases - look into com.google.gwt.user.client.Event.addNativePreviewHandler(NativePreviewHandler) for how this can be done.
I'm not seeing any other option right away - all of the actual logic for handling the keydown is wrapped up in the inner class in the private method of com.google.gwt.user.client.ui.SuggestBox.addEventsToTextBox(), leaving no options for overriding it.