When we set the tab an icon and text, you can see the icon is horizontally aligned with tab text. But if you want to place the icon above the tab label, you have to use a custom view to achieve it.
Java
class ViewPagerAdapter extends FragmentPagerAdapter
{
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager)
{
super(manager);
}
#Override
public Fragment getItem(int position)
{
return mFragmentList.get(position);
}
#Override
public int getCount()
{
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title)
{
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
#Override
public CharSequence getPageTitle(int position)
{
return mFragmentTitleList.get(position);
}
}
Xamarin.Android
class ViewPagerAdapter : FragmentPagerAdapter
{
private List<Android.Support.V4.App.Fragment> mFragmentList = new List<Android.Support.V4.App.Fragment>();
private List<string> mFragmentTitleList = new List<string>();
public ViewPagerAdapter(Android.Support.V4.App.FragmentManager manager)
{
//base.OnCreate(manager);
}
public override int Count
{
get
{
return mFragmentList.Count;
}
}
public override Android.Support.V4.App.Fragment GetItem(int postion)
{
return mFragmentList[postion];
}
public CharSequence GetPageTitle(int position)
{
return mFragmentTitleList[position];
}
public void addFragment(Android.Support.V4.App.Fragment fragment, string title)
{
mFragmentList.Add(fragment);
mFragmentTitleList.Add(title);
}
}
What's that? when the super(manager) be covert to xamarin android.
CharSequence GetPageTitle. they got a error-> cannot be used as return type
class ViewPagerAdapter : FragmentPagerAdapter
{
private List<Android.Support.V4.App.Fragment> mFragmentList = new List<Android.Support.V4.App.Fragment>();
private List<string> mFragmentTitleList = new List<string>();
public ViewPagerAdapter(Android.Support.V4.App.FragmentManager manager)
: base(manager)
{
}
public override int Count
{
get
{
return mFragmentList.Count;
}
}
public override Android.Support.V4.App.Fragment GetItem(int postion)
{
return mFragmentList[postion];
}
public override ICharSequence GetPageTitleFormatted(int position)
{
return new Java.Lang.String(mFragmentTitleList[position]);
}
public void AddFragment(Android.Support.V4.App.Fragment fragment, string title)
{
mFragmentList.Add(fragment);
mFragmentTitleList.Add(title);
}
}
Related
I have a iterator pattern. But I want to make it generic. So that you can have strings and numbers. Because now you only can put strings in the list items.
So I have this:
public interface IIterator< out T>
{
void First();
T Next();
bool IsDone();
T CurrentItem();
}
public interface IAggregate< out T>
{
IIterator <T> CreateIterator();
}
}
public class Science : IAggregate<T>
{
private LinkedList<string> Subjects;
public Science()
{
Subjects = new LinkedList<string>();
Subjects.AddFirst("Maths");
Subjects.AddFirst("Comp. Sc.");
Subjects.AddFirst(99);// So this of course fails
}
public IIterator<T> CreateIterator()
{
return new ScienceIterator<T>(Subjects);
}
}
public class ScienceIterator : IIterator
{
private System.Collections.Generic.LinkedList<string> Subjects;
private int position;
public ScienceIterator(LinkedList<string> subjects)
{
this.Subjects = subjects;
position = 0;
}
public void First()
{
position = 0;
}
public string Next()
{
return Subjects.ElementAt(position++);
}
public bool IsDone()
{
if (position < Subjects.Count)
{
return false;
}
else
{
return true;
}
}
public string CurrentItem()
{
return Subjects.ElementAt(position);
}
}
So my question is, is this possible in the default C# collection? Or you have to make your own LinkedList?
Thank you
I'm trying to create a custom control which has a collection of items, but nothing appears on design-time even if I rebuild the project.
(Parents) is custom control
How can I make it appear in the collection editor without losing it after rebuilding the project.
public class ItemsTest : UserControl
{
Parents parent;
ObjectCollections itm ;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ObjectCollections Items { get { return itm; } }
public ItemsTest ()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
itm = new ObjectCollections(this);
parent = new Parents();
}
}
public class ObjectCollections : CollectionBase
{
private List<Parents> _contents;
private ItemsTest itemstest = null;
public ObjectCollections(ItemsTest owner)
{
_contents = new List<Parents>();
this.itemstest = owner;
}
public int IndexOf(Parents item)
{
return _contents.IndexOf(item);
}
public void Insert(int index, Parents item)
{
_contents.Insert(index, item);
}
public void RemoveAt(int index)
{
_contents.RemoveAt(index);
}
public Parents this[int index]
{
get
{
return _contents[index];
}
set
{
_contents[index] = value;
}
}
public void Add(Parents item)
{
_contents.Add(item);
this.itemstest.Controls.Add(item);
this.itemstest.Invalidate();
}
public void Clear()
{
_contents.Clear();
}
public bool Contains(Parents item)
{
if (_contents.Contains(item))
return true;
return false;
}
public void CopyTo(Parents[] array, int arrayIndex)
{
for (int _oj = 0; _oj < Count; _oj++)
{
array.SetValue(_contents[_oj], arrayIndex++);
}
}
public int Count
{
get { return _contents.Count; }
}
public bool IsReadOnly
{
get { return false; }
}
public bool Remove(Parents item)
{
return _contents.Remove(item);
}
IEnumerator<Parents> IEnumerable<Parents>.GetEnumerator()
{
//some code
}
IEnumerator IEnumerable.GetEnumerator()
{
//some code
}
}
When I try to add items into the collection editor, rebuild the project, and reopen the collection editor nothing is shown in it.
I have a ComboBox containing Unicode symbols, the font is set to a Unicode-Supporting font and it displays them just fine. But the DropDown section seems to use a standard font which cannot display these Unicode symbols. Is there a way to change this inside the properties or do I have to create a customized ComboBox control?
EDIT:
My Code:
public class MainWindow : Form {
...
public BindingList<Sound> Sounds { get; set; } = new BindingList<Sound>();
public MainWindow() {
InitializeComponent();
this.comboBox.DataSource = this.Sounds;
}
...
}
public class Sound {
public char Symbol { get; private set; }
public Sound(char symbol) {
this.Symbol = symbol;
}
public override int GetHashCode() {
return this.Symbol.GetHashCode();
}
public override bool Equals(object obj) {
if(obj is Sound) {
return this.Symbol == ((Sound)obj).Symbol;
}
return base.Equals(obj);
}
public override string ToString() {
return this.Symbol.ToString();
}
public void Play() {
...
}
}
Im using the MVVMCross 4.4.0 and my FirstView is a List View like WhatsApp. When I click an item, my SecondView is a common view with just a field to update a property and change my FirstView, but this is not happen.
My First View Code
public sealed partial class MyOrdersView : MvxViewController
{
UITableView tableView;
public MyOrdersView() : base("MyOrdersView", null)
{
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
tableView = new UITableView
{
Frame = new CoreGraphics.CGRect(0, 0, View.Bounds.Width, View.Bounds.Height),
CellLayoutMarginsFollowReadableWidth = true,
};
Add(tableView);
var tableSource = new MvxSimpleTableViewSource(tableView, OrderCell.Key, OrderCell.Key);
tableView.Source = tableSource;
var set = this.CreateBindingSet<MyOrdersView, Core.ViewModels.MyOrdersViewModel>();
set.Bind(tableSource).To(vm => vm.Tasks);
set.Bind(tableSource).For(s => s.SelectionChangedCommand).To(vm => vm.ItemSelectedCommand);
set.Apply();
tableView.ReloadData();
Title = "Meus Pedidos";
AppDelegate app = UIApplication.SharedApplication.Delegate as AppDelegate;
NavigationItem.SetLeftBarButtonItem(
new UIBarButtonItem(UIImage.FromBundle("threelines")
, UIBarButtonItemStyle.Plain
, (sender, args) => app.SidebarController.ToggleMenu()), true);
}
}
And ViewModel
public class MyOrdersViewModel : BaseViewModel
{
private IOrderService orderService;
public ObservableCollection<ValOrders2TO> tasks;
private MvxCommand<ValOrders2TO> _itemSelectedCommand;
public MyOrdersViewModel(IOrderService orderService)
{
this.orderService = orderService;
tasks = orderService.getAvailableOrders();
searchMyOrders();
}
private async Task<bool> searchMyOrders()
{
orderService.clearAvailableOrders();
orderService.addAllAvailableOrders(await orderService.searchMyOrders());
return true;
}
public ObservableCollection<ValOrders2TO> Tasks
{
get { return tasks; }
set { tasks = value; RaisePropertyChanged(() => Tasks); }
}
public ICommand ItemSelectedCommand
{
get
{
_itemSelectedCommand = _itemSelectedCommand ?? new MvxCommand<ValOrders2TO>(DoSelectItem);
return _itemSelectedCommand;
}
}
private void DoSelectItem(ValOrders2TO item)
{
ShowViewModel<MyOrdersDetailModel>(new { idOrder = item.id });
}
}
My Second View Code
public sealed partial class MyOrdersDetailView : MvxViewController<MyOrdersDetailModel>
{
public MyOrdersDetailView() : base("MyOrdersDetailView", null)
{
//ViewDidLoad();
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var btnBack = UIButton.FromType(UIButtonType.System);
btnBack.Frame = new CGRect(2, 35, 50, 20);
btnBack.SetTitle("Voltar", UIControlState.Normal);
Add(btnBack);
var set = this.CreateBindingSet<MyOrdersDetailView, Core.ViewModels.MyOrdersDetailModel>();
set.Bind(txtItemDes).To(vm => vm.txtItemDes);
set.Bind(btnUpdate).To(vm => vm.update);
set.Apply();
}
}
And the ViewModel
public class MyOrdersDetailModel : MvxViewModel
{
public ValOrders2TO _valItem;
public INC<string> txtItemDes = new NC<string>();
public MyOrdersDetailModel(IMessageService messageService, IOrderService orderService)
{
}
public ValOrders2TO Item
{
get { return _valItem; }
set { _valItem = value; RaisePropertyChanged(() => Item); }
}
public void Init(ValOrders2TO item)
{
Item = item;
ConfigProp();
}
void ConfigProp()
{
txtItemDes.Value = Item.itemsDes;
}
public IMvxCommand Update
{
get
{
return new MvxCommand(() => updateOrder());
}
}
private bool updateOrder()
{
Item.itemsDes = txtItemDes.Value;
return true;
}
public IMvxCommand CloseCommand
{
get { return new MvxCommand(() => Close(this)); }
}
}
This is my Bean Code
public class ValOrders2TO
{
//[JsonProperty()]
public int id { get; set; }
//[JsonProperty()]
public string itemsDes { get; set; }
}
And this is my OrderCell
public partial class OrderCell : MvxTableViewCell
{
public static readonly UINib Nib = UINib.FromName("OrderCell", NSBundle.MainBundle);
public static readonly NSString Key = new NSString("OrderCell");
private readonly MvxImageViewLoader _loader;
public OrderCell(IntPtr handle) : base(handle)
{
this.DelayBind(() =>
{
var set = this.CreateBindingSet<OrderCell, Core.ValOrders2TO>();
set.Bind(lblItemDes).To(item => item.itemsDes);
set.Apply();
});
}
public static OrderCell Create()
{
return (OrderCell)Nib.Instantiate(null, null)[0];
}
}
I know how to remove the items from my ListView like this:
orderService.deleteAvailableOrder(Item);
But I don't know how to update the items list.
Following attached my print screens
Try to implement RaisePropertyChanged for
public string itemsDes { get; set; }
I have an assignment to implement a linear linked list using generics in C# console application.
The class should also contain a print() method to print the elements of the list.
Conditions for Linear List are to be as a long type (CNodeLong) or String Type (CNodeString), both inherited from CNode with virtual function Print().
I have a problem implementing the printing method. I don't know where should it stand, and how to override it.
Here is my CNode class and CList class:
public class CNode<T>
{
private CNode<T> next;
private T item;
public CNode<T> Next
{
get { return next; }
set { next = value; }
}
public T Item
{
get { return item; }
set { item = value; }
}
public CNode(T item)
: this(item,null)
{
}
public CNode(T item, CNode<T> next)
{
this.item = item;
this.next = next;
}
}
class CList<T>
{
private CNode<T> first;
private CNode<T> last;
private int count;
public CNode<T> First
{
get { return first; }
}
public CNode<T> Last
{
get { return last; }
}
public int Count
{
get { return count; }
}
public CList(string strListName)
{
count = 0;
first = last = null;
}
}
You probably should override ToString method and add the virtual Print method to CNode.
(I've also added the PrintList method to CList):
public class CNode<T>
{
...
public override string ToString()
{
return item.ToString();
}
virtual public void Print()
{
Console.WriteLine(item);
}
}
class CList<T>
{
...
public void PrintList()
{
CNode<T> current = first;
while (current != null)
{
Console.WriteLine(current.ToString());
current = current.Next;
}
}
}
Then you can override the virtual method in the child classes:
public class CNodeString : CNode<string>
{
public CNodeString(string item) : base(item) { }
override public void Print()
{
Console.WriteLine("Printing from CNodeString");
base.Print();
}
}
public class CNodeLong : CNode<long>
{
public CNodeLong(long item) : base(item) { }
override public void Print()
{
Console.WriteLine("Printing from CNodeLong");
base.Print();
}
}