I'm creating a new Dialog view in Droid platform, using the CrossUI.Droid.Dialog project. I'm also using bindings provided by the MvvmCross Framework.
Here is the code I have in the Droid view, to create and bind the Dialog:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
DroidResources.Initialise(typeof(Resource.Layout));
Root = new RootElement()
{
new Section("Private Configuration")
{
new EntryElement("Name:").Bind(this, "{'Value':{'Path':'Configuration.Name'}}"),
new EntryElement("Description:").Bind(this, "{'Value':{'Path':'Configuration.PrivateDescription'}}"),
new BooleanElement("Active?").Bind(this, "{'Value':{'Path':'Configuration.Active'}}")
},
new Section("Display Configuration")
{
new StringElement("Header Title")
{
Click = (o, e) => GoToHeaderTitleActivity(),
LayoutName = "dialog_rootNavigate"
}
}
};
}
When I run the app, the dialog is shown and the bindings are correct.
The problem I have is when I try to write something in one of the EntryElement, the focus just goes somewhere else... This only happens when I have 'Text Prediction' enabled.
I've checked the sample in Android.Dialog and all seems to work just fine.
I'm using a Galaxy Tab 2 7.0, with ICS 4.0
Does anyone had this problem?
Found the answer!!
Apparently there is a known issue in Android where EditText controls and ListView don't play nice. This is not a problem with MvvmCross or Monodroid.Dialog.
To overcome this (and I'm guessing this is the reason for it's existence?) use the MvxLinearDialogActivity when developing forms using dialog. The issue instantly disappears.
As the comment in the class says:
DialogActivity based on a linear view, this will solve all edittext related focus problems when using elements
suggestions at Focusable EditText inside ListView doesn't help for example
Related
I am trying a simple Android app using Xamarin Forms with C# for the coding. In my Main.axml there's a button, on clicking which I'd like to go to a new page, say XInfo.axml.
Now this is my MainActivity.cs:
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Xamarin.Forms;
namespace AlberoPizza
{
[Activity(Label = "Albero Pizza", MainLauncher = true, Icon="#drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button btn = FindViewById<Button>(Resource.Id.MyButton);
btn.Clicked += (object sender, EventArgs e) => {
};
}
}
}
Now, I am finding it difficult to structure code inside my Lambda which would handle the navigation to the page, whose name I mentioned. There is no Navigation Bar and there cannot be any navigation bar. Also, for the existing code block, I am getting this error, which is quite weird to me:
Error CS0311: The type 'Xamarin.Forms.Button' cannot be used as type parameter 'T' in the generic type or method 'Android.App.Activity.FindViewById(int)'. There is no implicit reference conversion from 'Xamarin.Forms.Button' to 'Android.Views.View'. (CS0311) (AlberoPizza)
I thought this is how we usually find controls in Android app Xamarin. Can you help me complete the code for this? I'm sure it's a pretty basic type of scenario. There is this persistent error on the one hand and the code to navigate to XInfo.axml on the other. I've tried stuff like Activator.CreateInstance, the PushAsync, etc. inside the lambda, but more errors show up and entire thing becomes more and more complicated.
I am trying to popup a dialog over my fullscreen primary stage in javafx. When I create my popup, it is unexpectedly hidden behind my fullscreen primary stage until the stage is removed from fullscreen mode (via ESC). If I make my primary stage maximized and undecorated instead of fullscreen, then my popup will appear on top of the primary stage as expected.
Am I missing something about how fullscreen mode is different than maximized and undecorated mode? Am I using fullscreen mode improperly?
I am using java version 1.8.0_20 on CentOS 6.5 with Gnome.
Here is my SSCCE:
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.stage.*;
public class TestApplication extends Application {
private Stage primaryStage;
public static void main(String[] arguments) {
launch(arguments);
}
public void start(Stage stage) {
this.primaryStage = stage;
// Create a fullscreen primary stage.
primaryStage.setTitle("Main Stage");
primaryStage.setScene(new Scene(createRoot()));
primaryStage.setFullScreen(true);
primaryStage.show();
}
private Parent createRoot() {
Button button = new Button("Show popup");
button.setOnAction((event) -> showPopup());
return button;
}
private void showPopup() {
// Create a popup that should be on top of the primary stage.
Stage popupStage = new Stage();
popupStage.setScene(new Scene(createPopupRoot()));
popupStage.setTitle("Popup Stage");
popupStage.initModality(Modality.WINDOW_MODAL);
popupStage.initOwner(primaryStage);
popupStage.show();
}
private Parent createPopupRoot() {
return new Label("This is a popup!");
}
}
After repeating this problem with java version '1.8.0_40', I finally found how to fix this problem!
popupStage.initStyle(StageStyle.UTILITY);
Stage.initStyle(StageStyle) -- JavaFX 8
Giving the popup a style of StageStyle.UTILITY seems to keep the popup in front of the fullscreen window even when clicking outside of the popup.
I saw this same issue when using the new Alert class in java 1.8.0_40, and setting the style to StageStyle.UTILITY fixed that as well (Dialog.initStyle(StageStyle) -- JavaFX 8).
I don't know why this works.
Side Note:
It looks like removing the call to popupStage.initOwner(...) allows the popup to appear above the full screen application, but clicking outside of the popup causes the popup to disappear.
Assuming you're on a Mac, this is a known issue, which is fixed in 8u40. You may need to use the ea version until the full release.
The basic history of this bug is that JavaFX implemented its own full screen implementation, in order to support OS X versions prior to 10.7 (which didn't have a native full-screen mode). That implementation uses an "exclusive mode", which prevents other windows from showing. This can get pretty bad: for example ComboBoxs won't work... The issue is fixed in 8u40 by using the native mode (since OS X versions prior to 10.7 are no longer supported anyway).
Note that if you don't programmatically set full screen mode, and allow the user to go to full screen using the Mac OS button on the window title bar, then the issue should not arise.
I am trying to open an email client just like using mail me tag.
But I want to use my custom widget, which is not hyperlink, anchor or so. I added a DOM handler to my widget to listen to clicks:
public class VContactWidget extends VHorizontalLayout implements ClickHandler {
private HandlerRegistration clickHandler;
public VContactWidget() {
// added some content here
clickHandler = addDomHandler(this, ClickEvent.getType());
}
#Override
public void onClick(ClickEvent event) {
Window.open("mailto:john.doe#mail.com", "_blank", "");
}
}
Everything is working fine except one detail: When the widget is clicked, new empty browser tab will open with url set to mailto:john.doe#mail.com. I don't want the new tab opened. Can I avoid it somehow?
Note I set _blank parameter, as used in many examples. I also tried to use empty string or some other values as well. I looked into documentation, but didn't find anything useful.
https://developer.mozilla.org/en-US/docs/Web/API/window.open
One solution may be to use Anchor, but my component is more complex, not just single <a> link.
Another detail to note may be application server - I am using Tomcat 7 now.
Trying to fire native event on hidden Anchor programatically did not work for me. (Which does not mean it cannot be done.)
This is, how I actually solved my problem: Instead of Window.open(), I used following call:
public void onClick(ClickEvent event) {
Window.Location.assign("mailto:john.doe#mail.com");
}
This is not something that you can control. Whether this link opens in a new tab or a new window depends on the browser settings and user preferences.
I don't think it will make a difference if you use an Anchor or Window.open. In either case, the behavior may be different in different browsers. Also remember that for some users a click on this link will open Outlook or Mail, while for other users it will open Gmail in a browser window.
UPDATE:
If you want an exact behavior of an <a> element, create a hidden anchor element and fire a click on it when a user clicks on your composite widget.
Firing click event from code in gwt
I tried to create a fileUploader with GWT.
Here is the problem, while I was adding ChangeHandler to fileUploader, I found that the behavior of IE and Chrome are different. If I choose the same file I uploaded, IE will trigger the onChange(), while Chrome won't. That's too weird. Can anybody tells me if it is a bug of GWT of not??
FileUpload fileUploader = new FileUpload();
fileUploader.addChangeHandler(new ChangeHandler(){
#Override
public void onChange(ChangeEvent event)
{
submitButton.setEnabled(true);
}
});
There are browser discrepancies that GWT cannot hide. The only mean to really reset a FileUpload in a cross-browser way, is to create a new one to replace the previous instance.
I would like to trigger a click on the browse button on a hidden FileUpload widget.
The following code works fine on IE 6+, but doesn't work in FireFox.
final FileUpload upload = new FileUpload();
upload.setVisible(false);
upload.setName("uploadFormElement");
panel.add(upload);
panel.add( new Button("Select File", new ClickListener()
{ public void onClick(Widget pSender)
{ jsClickUpload( upload.getElement() ); } }));
native void jsClickUpload( Element pElement ) /*-{ pElement.click(); }-*/;
How can I achieve the same in FireFox (and possibly other browsers)?
The solution can be read here:
http://www.quirksmode.org/dom/inputfile.html
in the last paragraph:
The click() method allows you to
simulate a click on a form field.
Checkboxes get toggled, radios
selected, and so on. Unfortunately
Mozilla and Opera haven't added this
method to file upload fields. I wonder
why, adding it is not really a
security risk since the worst that can
happen is that the file selection
window pops up.
have you tried calling the onClick() method directly?
The click method is currently in the process of being implemented in FF 4. It is being discussed what security rules will be implemented and it sounds like it will be similar to Window.open and must be the direct result of a user action and not a timer or load.