MonoTouch.Dialog: How to make a RadioElement multiline? - xamarin.ios

I am trying to develop an app with MonoTouch. For some screens I create the UI in code. I have a dynamically created RadioGroup with normally two to four RadioElements (choices). Sometimes the text (dynamic too) is too long for the RadioElement so that on an iPhone the text gets shorted by ... at the end.
I have googled and found no suggestion on how to create multiline RadioElements. I know you can create a MultilineElement if you want text over several lines, but how would I go about combining the two? I assume I have to inherit from RadioElement and override some events, but which? Is it the MonoTouch.UIKit.UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv) event?
Alternatively, how would you go about creating a MultilineElement that get a check mark on it when it got pressed/selected?
Or should I be thinking completely different? Are there some other components that could solve this in a simpler way?

This is a sort-of solution (at least it solves my problem):
public class MultilineRadioElement : RadioElement
{
public MultilineRadioElement (string caption, string group)
: base(caption, group) { }
public override MonoTouch.UIKit.UITableViewCell GetCell
(MonoTouch.UIKit.UITableView tv)
{
var cell = base.GetCell (tv);
cell.TextLabel.Lines = 2;
return cell;
}
}
When I now use a MultilineRadioElement instead of a RadioElement the text shows on two lines. For me two lines are enough. If the text is even longer and you still want to fit it inside the RadioElement at its current size you will probably have to calculate the size of the text and for example set the font in cell.TextLabel.Font to a more appropriate font.
I don't know how to make the RadioElement itself get bigger, so this is my best suggestion.
By the way, you should probably also add
protected override MonoTouch.Foundation.NSString CellKey
{
get { return base.CellKey; }
}
to the MultilineRadioElement as the intellisense in my Xamarin Studio suggests that this should be done when overriding GetCell, although it seems to work without it as well.
I am very happy if someone has an even better suggestion!! (yes, two exclamation marks :) )

Related

Focus item listview on Android dosent work

I searched lot on internet to find a solution for my problem but I haven't found a answer. I hope someone can help me.
I have a Android application where I made a fragment with 3 tabs. Every tab had a different layout and in every layout there is a listview with different id. The problem is that, when i click on item of listview, only the item of the first tab take focus and background was set to green. In the other tabs the item is selected but focus don't change the background item color.
I had clear the focus on the first tab if was selected but this don't resolve the problem.
this is the code that I implementer on tab
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int pos, long arg3) {
view.setSelected(true);
selectedBusiness = businessList.get(pos);
buttonModify.setEnabled(true);
}
});
Any idea?
Thank Max
I found the solution.
The error in my case was made from
ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.my_business_item);
I don't know why but the problem was the layout. In the other two tabs, I used the adapter with another layout android.R.layout.simple_list_item_1. With this layout the focus dosen't work. With my simple layout it works.

Xamarin.Forms.DatePicker Text color

For Xamarin.Forms.DatePicker It is not obvious that the date field is "tapable" I want to change the text color of it to blue so the user will think it is clickable?
I see a background color property but not forecolor/text color?
Let me know how I can do that.
I did it just creating a class like that on my Android Project and making no changes on my Forms Pages:
using Xamarin.Forms;
using xxxx.Droid;
[assembly: ExportRenderer(typeof(Xamarin.Forms.DatePicker), typeof(MyDatePickerRederer))]
namespace xxxx.Droid
{
public class MyDatePickerRederer : Xamarin.Forms.Platform.Android.DatePickerRenderer
{
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.DatePicker> e)
{
base.OnElementChanged(e);
this.Control.SetTextColor(Android.Graphics.Color.Black);
}
}
}
I don't think that the forecolor/text color is accessible at this time and I'm not sure if it will be in the future or not. Typically what you would do in this scenario is create a Custom Renderer to get down into the native implementation of the UIDatePicker control for iOS and change it's properties there. The problem with that in this case is that if you look through the iOS SDK documentation as well, I don't believe there is a way to customize the text on the UIDatePicker picker control. This is why you can't do it in Xamarin.Forms either.
At this point you will probably have to create your own custom control/renderer to make such a small change. Frustrating, I know, but unfortunately that this point I don't think you can actually accomplish the simple thing you are looking to do. :-(

JavaFX 2.1 TableView that includes WebView cells

I want to create a JavaFX table that, in the cells of one column, allows the user to edit XHTML text. I only need very basic formatting capabilities like bold, italic, striketrough.
I have already managed to implement this by using my own subclass of TableCell and using a WebView for each cell (HTMLEditor would of course have been another choice, but my guess is that for my requirements, WebView should be sufficient).
However, to make editing comfortable for the user, I need the following features:
1. The cell height needs to resize if the user enters multi-line text.
2. A context menu (or, if not possible, some other menu or button) should allow formatting parts of the text in a cell as described above (bold, italic..)
Has anybody been successful in implementing something similar ? I have seen suggestions on the web, but they rarely included code samples.
I have succedded doing something similar.
I figured I can share some of the basic clues that allowed me to achieve it.
Resize the whole WebView. For that, the whole WebView must be an editable html page. You achive that by setting contenteditable to true:
<body contenteditable='true' id='content'></body>
You can have a context menu over a webview. But it is something tricky, as you must first disable the original context menu associated to it.
WebView editView;
...
EventDispatcher originalDispatcher = editView.getEventDispatcher();
editView.setEventDispatcher(new WebmenuEventDispatcher(originalDispatcher));
And this is the event dispatcher class:
public class WebmenuEventDispatcher implements EventDispatcher {
private EventDispatcher originalDispatcher;
public WebmenuEventDispatcher(EventDispatcher originalDispatcher) {
this.originalDispatcher = originalDispatcher;
}
#Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
if (event instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) event;
if (MouseButton.SECONDARY == mouseEvent.getButton()) {
mouseEvent.consume();
// Show our own menu
cmEdit.show(editView.getScene().getWindow(), mouseEvent.getScreenX(), mouseEvent.getScreenY());
}
}
return originalDispatcher.dispatchEvent(event, tail);
}
}
Now, for setting the font from within that menu, you need a bidirectional Java<->javascript bridge and use some javascript in the webview side.

MonoTouch.Dialog: Dismissing keyboard by touching anywhere in DialogViewController

NOTE: There are two similar SO questions (1) (2), but neither of them provides an answer.
TL;DR: How can one dismiss the keyboard in a MonoTouch.Dialog by letting the user touch any empty space in the view?
I'm writing an app using MonoTouch.Dialog and a UITabBarController. One of my tabs is "Settings"...
When the user starts typing, the keyboard obstructs the tabbar...
Using MonoTouch.Dialog, the only way to dismiss the keyboard is to go to the last field and press the "return" key. Considering the fact that the user cannot press any tab until the keyboard is gone, I would like a better way to do it. Namely, to dismiss if the user taps anywhere else on the screen.
Without MonoTouch.Dialog, it's a snap: simply override TouchesBegan and call EndEditing. But this doesn't work with MT.D. I've tried subclassing DialogViewController and overriding TouchesBegan there, but it doesn't work. I'm currently at a loss.
Or, I wonder, would I be better off ditching the tabbar so I can use a UINavigationController with a "Back" button on top, which won't be hidden by the keyboard?
I suggest you use a tap gesture recognizer that will not cause interference with the TableView event handlers:
var tap = new UITapGestureRecognizer ();
tap.AddTarget (() => dvc.View.EndEditing (true));
dvc.View.AddGestureRecognizer (tap);
tap.CancelsTouchesInView = false;
You missed my question about it also: Can the keyboard be dismissed by touching outside of the cell in MonoTouch.Dialog?
:-)
This is my #1 feature request for MonoTouch.Dialog.
To answer your question: No. It is not possible. I have searched and asked around and have not found any answers.
I assume because it is just a sectioned (grouped) table and if it wasn't sectioned, there wouldn't be any spot to click. However, that is just my speculation.
I wish that miguel or someone that works on monotouch would answer this and say if it is even possible. Possibly a future enhancement?
I figured out a workaround that satisfies me well enough, so I'm answering my own question.
// I already had this code to set up the dialog view controller.
var bc = new BindingContext (this, settings, "Settings");
var dvc = new DialogViewController (bc.Root, false);
// **** ADD THIS ****
dvc.TableView.DraggingStarted += (sender, e) => {
dvc.View.EndEditing (true);
};
This will dismiss the keyboard whenever the user drags the view a little bit. There's no touch event I could find associated with the tableview, so this is the next best thing. I'd welcome any other ideas. Cheers!
One workaround to use the dragging gesture instead of the tap as proposed (that do not interfere with the table view gestures) is to override MonoTouch.Dialog.DialogViewController.SizingSource (or MonoTouch.Dialog.DialogViewController.Source if you don't want uneven rows) and give it to the DialogViewController. I don't know if it is very clean or safe.
public class CustomTableViewSource : MonoTouch.Dialog.DialogViewController.SizingSource
{
public CustomTableViewSource(MonoTouch.Dialog.DialogViewController dvc) : base(dvc)
{
}
public override void DraggingStarted(UIScrollView scrollView)
{
base.DraggingStarted(scrollView);
if (scrollView != null)
{
scrollView.EndEditing(true);
}
}
}

WebView underneath Andengine

I'm trying to put a joypad made with AndEngine on a WebView that will be the view of an ipCamera. How can I do? I've searched a lot about that, but still haven't found the solution. Thank you all very much
You didn't mention what version of AndEngine you are using.
If you are using GLES2 (same technique may work for the GLES1 branch but I have not verified that), look at the AndEngine TextBreakExample.
That example shows how to use the org.andengine.opengl.view.RenderSurfaceView in combination with another layout like a LinearLayout. The "other layout" can contain anything - this example uses an EditText, but you should be able to use a WebView using the same technique.
Be sure and check the res/layout/textbreakexample.xml file. Also note these extra methods in the TextBreakExample.java file
#Override
protected int getLayoutID() {
return R.layout.textbreakexample;
}
#Override
protected int getRenderSurfaceViewID() {
return R.id.textbreakexample_rendersurfaceview;
}
https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/TextBreakExample.java
https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/res/layout/textbreakexample.xml
Also might check out this layout file
https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/res/layout/xmllayoutexample.xml

Resources