-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'BindingChanges' of https://github.com/slodge/MvvmCross …
…into mac-play
- Loading branch information
Showing
6 changed files
with
126 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
CrossUI/CrossUI.Droid/Dialog/Elements/SimplePickerElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Collections; | ||
using System.Linq; | ||
using Android.App; | ||
using Android.Content; | ||
|
||
namespace CrossUI.Droid.Dialog.Elements | ||
{ | ||
public class SimplePickerElement : StringDisplayingValueElement<object> | ||
{ | ||
public SimplePickerElement(string caption, object value = null, string layoutName = null) | ||
: base(caption, value, layoutName ?? "dialog_multiline_labelfieldbelow") | ||
{ | ||
Click = delegate { ShowDialog(); }; | ||
} | ||
|
||
IList _entries = new object[0]; | ||
public IList Entries | ||
{ | ||
get { return _entries; } | ||
set { _entries = value; BindItemArray(); } | ||
} | ||
|
||
private void BindItemArray() | ||
{ | ||
var arr = new object[Entries.Count]; | ||
Entries.CopyTo(arr, 0); | ||
_itemArray = arr.Select(x => Format(x)).ToArray(); | ||
} | ||
|
||
string[] _itemArray = new string[0]; | ||
|
||
private int FindSelectedIndex() | ||
{ | ||
var i = 0; | ||
foreach (var x in Entries) | ||
{ | ||
if (x == Value) | ||
return i; | ||
i++; | ||
} | ||
return -1; | ||
} | ||
|
||
private void ShowDialog() | ||
{ | ||
var context = Context; | ||
if (context == null) | ||
{ | ||
Android.Util.Log.Warn("RadioDialogElement", "No Context for Edit"); | ||
return; | ||
} | ||
|
||
new AlertDialog.Builder(context) | ||
.SetTitle(base.Caption) | ||
.SetSingleChoiceItems(_itemArray, FindSelectedIndex(), (o, e) => OnClick(o, e)) | ||
.Create() | ||
.Show(); | ||
} | ||
|
||
protected virtual void OnClick(object o, DialogClickEventArgs e) | ||
{ | ||
OnUserValueChanged(Entries[e.Which]); | ||
((AlertDialog)o).Dismiss(); | ||
} | ||
|
||
protected override string Format(object value) | ||
{ | ||
if (value == null) | ||
return string.Empty; | ||
return value.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters