.Net Monodroid spinner auto-fill - forms

I am using .Net and Monodroid to develop Android applications, however I seem to have hit a wall when it comes to filling in a Spinner at run time, as I do not have access to the [Spinner Object].SetAdapter(...) method. I have been to both
developer.android.com/resources/tutorials/views/hello-spinner.html
and
android.xamarin.com/Tutorials
as well as
stackoverflow.com/questions/3958866/how-to-change-the-contents-of-spinner-on-run-time-in-android
and everything relies on this method. Is this a limitation of the unregistered version? Because they do not say anything about feature-limits here android.xamarin.com/DownloadTrial
Any help will be appreciated.

In Mono for Android, many cases where Java will have getXXXX/setXXXX methods get translated into properties named XXXX, in order to be more .NET friendly. In this case, Spinner.setAdapter() in Java becomes Spinner.Adapter in Mono for Android:
Spinner spinner = FindViewById<Spinner> (Resource.Id.spinner);
spinner.Adapter = new ArrayAdapter...
Xamarin also has a Spinner tutorial available here that might help you get going.

Solved it - there is an Adapter property that can be used to access the Adapter.
Also it turns out you must check if the adapter is null first - you cannot read a null object :)
if (_itemlist.Adapter == null)
{
adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerItem, items);
}
the only problem is that it does not automatically refresh and the invalidate(...) method does not cause it to redraw with the new items...

Related

Unity WebGL Mobile browser workaround and keyboard input fix?

Hey everyone so I read that unity doesn't really support mobile browsers for WebGL games. im using 2020.1.4.And sure enough, the game gets a bit distorted by not being scaled properly. it's like the camera is bigger so it shows on the screen that blue color. I tried some things, setting width and height to auto or removing config.devicePixelRatio = 1; as suggested by a friend but nope! still looks horrible! And if that wasn't enough the keyboard doesn't show up when clicking on form fields. i tried this one
https://github.com/eforerog/keyboardMobileWebGLUnity
which displayed an error when pressed on and this one
https://github.com/dantasulisses/WebMobileInputFix which just didn't even compile!
Any ideas, please?
I did my research and tried every plugin I could find. I used Unity 2020.3.28f1 and tested both on Android-phone and iPhone.Here is my report.
These plugins don't work:
https://unitylist.com/p/f58/Unity-webgl-inputfield
https://github.com/eforerog/keyboardMobileWebGLUnity
https://github.com/dantasulisses/WebMobileInputFix
This plugin works, but you should use different settings for IOS and Android on same input field game object. If you use "prompt", it works for IOS only, and "overlay" works for Android only. Look for documentation in page:
https://github.com/unity3d-jp/WebGLNativeInputField
And this plugin works best at the moment. Yes, it is a bit ugly though, but it works.
https://github.com/kou-yeung/WebGLInput
And there is a fix for Unity 2021 for it:
https://github.com/kou-yeung/WebGLInput/releases/tag/1.0
There's a keyboard that overlays, when using it you just need to tap the notification to access it and then click the "back" button to hide it https://play.google.com/store/apps/details?id=com.fishstix.gameboard
I made this project that simply recreates a keyboard using buttons in unity.
I implemented it in a WebGL build successfully.
https://github.com/thetimeste/WebGL-Build-Keyboard-Unity.git
I would recommend using the native js window.prompt() fields as of writing. They have great cross-platform support, allow for extra features like special characters, emojis, copy and paste etc. and are pretty easy to set up. Once (or honestly if ever) Unity adds their own reliable implementation you can easily remove this lightweight implementation.
Create a .jslib file that has a function opening a window.prompt(description, currentText)
Return the result at the end of that function back to a unity object with a recipient script
Make a derivation from Unity's event system overwriting the OnApplicationFocus(bool focus) function (leaving it empty), to fix a sneaky Chrome Android bug.
That's it. The result should look something like in this demo: https://pop.demo.neoludic.games
If you want to save some development time on a feature that really should just be native in Unity, you can also check out my plugin based on the method above. https://neoludic-games.itch.io/pop-input
I also need to enable mobile virtual keyboard for running webgl on mobile device.
I've tried the code from your mentioned url. It gives you some idea on how to do
it, but the code are totally buggy and unusable. Now I am trying to implement it
by myself.

How to bind button click commands in ReactiveUI for iOS

I'm trying to learn ReactiveUI for a Xamarin.iOS project and I'm stuck on what should be a simple task. I am unable to bind a button click to a ReactiveCommand in the same way I can in my companion Xamarin.Android project. Here is the Android code that works fine:
this.BindCommand (ViewModel, x => x.ClickMe, view => view._button);
Here is the same pattern used in iOS:
this.BindCommand (ViewModel, x => x.ClickMe, view => view.GetForecastButton);
However, in iOS I get the following warning:
"Couldn't find a Command Binder for MonoTouch.UIKit.UIButton"
Does anyone know what I'm doing wrong? The astonishing thing is that I've looked up dozens of ReactiveUI iOS examples and I still haven't found one that has even a single button in the app. They all do something like show text from a bound property or show a UITableView from a collection in the ViewModel. I'm sure there is a more complete iOS example out there and if anyone knows of one please include in your answer. Many thanks.
You're doing everything correctly, but I believe you're being trolled by a Xamarin.iOS bug that affects ReactiveUI, where Type.GetType won't load assemblies. Paste this into your AppDelegate:
https://github.com/paulcbetts/starter-mobile/blob/master/Starter-iOS/AppDelegate.cs#L35
// NB: GrossHackAlertTiemâ„¢:
//
// Monotouch appears to not load assemblies when you request them
// via Type.GetType, unlike every other platform (even
// Xamarin.Android). So, we've got to manually do what RxUI and
// Akavache would normally do for us
var r = RxApp.MutableResolver;
(new ReactiveUI.Cocoa.Registrations()).Register((f,t) => r.Register(f, t));
(new ReactiveUI.Mobile.Registrations()).Register((f,t) => r.Register(f, t));

mobile web app - keyboard not appearing

I have a mobile web application, working well on simulator 5.1/6.0, xcode 4.5 for iphone.
But when I test on a real device (3gs, ios 5.1), I get a strange behavior: anywhere I place an input field html element, where I need the user to fill in something, I tap the field, it gains focus (I see the cursor), but the touch-keyboard does not come up and I can't type anything. If I try it on the sim, all is fine, the kb comes up.
I am not sure how to diagnose this... tried googling for some answers, haven't found any :(
any ideas?
thanks...
ok found the issue, seems like the app was not created using the latest Xcode template (it is a legacy app), so I removed the MainWindowxxx.xibs which I don't need, and used the code from a new XCode app template to initialize the app by programmatically creating the main view controller, and setting it as the window's rootViewController. And, of course, call [self.window makeKeyAndVisible]

Phonegap crashes when status bar tapped on iOS5 [duplicate]

I'm using Xcode 4.3.1 with Phonegap 1.4.1 to build an iPhone app. Whenever I tap the status bar to scroll to top, the app crashes with an EXC_BAD_ACCESS error.
I've tried implementing a number of suggestions such as this
.
I've also tried adding variations of the below code:
[[[theWebView subviews] objectAtIndex:0] setScrollsToTop:NO];
((UIScrollView*)[theWebView.subviews objectAtIndex:0]).scrollsToTop = NO;
to the
- (void) webViewDidFinishLoad:(UIWebView*) theWebView
{
...
}
within the AppDelegate.m
However, I've have been unable to resolve the issue. My main concern is to stop the app form crashing, any insight would be greatly appreciated.
I am using cordova 1.7 and have the same problem. I found a workaround though. You need to patch phonegap by commenting out the creation of invsible iframe which is injected by phonegap to communicate with the native side. In fact, this iframe causes all kinds of rendering issues, not only the status bar problem:
if (cordova.commandQueue.length == 1 && !cordova.commandQueueFlushing) {
// if (!gapBridge) {
// createGapBridge();
// }
// gapBridge.src = "gap://ready";
location = "gap://ready";
}
I didn't find any side effects after I've made the above change. However, I know people complain that some plugins stopped working, e.g. google analytics.

Eclipse - Blackberry SDK - Debugging on device: "details unavailable - not supported by VM"

I'm having a strange problem while debugging my Blackberry Application on a real device (BB Bold 9700). When I debug the same application within the BB emulator, the app runs fine, but when I run it on the real device, the app behaves differently (custom painting goes completely wrong). What's even worse is that my Eclipse environment seems to be unable to view live objects correctly while being at a break point (debug time).
I've added a screenshot to illustrate the strange behaviour:
As you can see, the app stops at the breakpoint within the IF statement, but the Variables pane says that the variable "methodName" equals null. Moreover, when I want to look at the variable "methodArguments" which is of type org.json.me.JSONArray, it says "details unavailable - not supported by VM".
Does anyone know what's going on here? My app works great on the emulator, but it's currently useless on the real device.
Thanks in advance!
I think I fixed it:
The problem was that I was laying out Fields on a manager that wasn't yet added to the viewstack.
What did the trick for me was overriding onDisplay() in the manager that contained the Fields that were displayed wrong:
protected void onDisplay()
{
//Make sure superclass is called
super.onDisplay();
/*You have to call "this.setDirty(true)" when you perform layout on a
*manager that isn't added to the viewstack. Then you can use
*"this.isDirty()" to determine whether you need to re-layout the fields
*when the manager becomes visible.*/
if(this.isDirty())
{
//I'm not sure if I need to use "invokeAndWait" and not "invokeLater"
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
for (int i = 0; i < getFieldCount(); i++)
{
/*This (custom) function makes sure the Field gets its
*size and position*/
layoutItem(getField(i));
}
}
});
//Make sure you set "dirty" to false, to make sure this only happens once
this.setDirty(false);
}
}
If anyone has a better solution, I'd be glad to hear it (and maybe improve my app).
org.json.me.JSONArray, it says "details unavailable - not supported by VM".
the JSON related stuff is not available on device running 4.5 and 4.6 BB OS. Import it into the code.
Download it from here.
https://github.com/douglascrockford/JSON-java
it is available as Open Source and then use it into your applications.