


Develop Android applications using C# + Xamarin - dynamically add controls
Using C# + Xamarin to develop Android applications--dynamically adding controls
public class MyOrders : Activity { private DynamicControl _dynaControl; public MyOrders() { _dynaControl = new DynamicControl(); } protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); try { SetContentView(Resource.Layout.MyOrders); var layout = (TableLayout)FindViewById(Resource.Id.myorders_layout); var header = AddHeader(); layout.AddView(header); layout.AddView(AddPendingServiceItem("Service 1")); layout.AddView(AddPendingServiceItem("Service 2")); layout.AddView(AddPendingServiceItem("Service 3")); layout.AddView(AddConfirmedServiceItem("Service 4")); layout.AddView(AddConfirmedServiceItem("Service 5")); layout.AddView(AddConfirmedServiceItem("Service 6")); layout.AddView(AddConfirmedServiceItem("Service 7")); } catch (Exception ex) { this.ShowAlert(ex.Message); } } public View AddHeader() { var header = new TableRow(this); header.LayoutParameters = new TableLayout.LayoutParams(TableLayout.LayoutParams.FillParent, TableLayout.LayoutParams.WrapContent); header.AddView(_dynaControl.NewText(this, "Service")); header.AddView(_dynaControl.NewText(this, "Status")); header.AddView(_dynaControl.NewText(this, "Created At")); header.AddView(_dynaControl.NewText(this, "Action")); return header; } public View AddPendingServiceItem(string serviceName) { var tableRow = new TableRow(this); tableRow.LayoutParameters = new TableLayout.LayoutParams(TableLayout.LayoutParams.FillParent, TableLayout.LayoutParams.WrapContent); tableRow.AddView(_dynaControl.NewText(this, string.Format("{0} ", serviceName))); tableRow.AddView(_dynaControl.NewText(this, string.Format("{0} ", "Pending"), Color.OrangeRed)); tableRow.AddView(_dynaControl.NewText(this, string.Format("{0} ", "2015-5-19 \r\n14:20:33"))); tableRow.AddView(_dynaControl.AddButton(this, "Details")); return tableRow; } public View AddConfirmedServiceItem(string serviceName) { var tableRow = new TableRow(this); tableRow.AddView(_dynaControl.NewText(this, string.Format("{0} ", serviceName))); tableRow.AddView(_dynaControl.NewText(this, string.Format("{0} ", "Confirmed"), Color.DarkGreen)); tableRow.AddView(_dynaControl.NewText(this, string.Format("{0}", "2015-5-19 \r\n 14:30:43"))); tableRow.AddView(_dynaControl.AddButton(this, "Rebook")); tableRow.LayoutParameters = new TableLayout.LayoutParams(TableLayout.LayoutParams.FillParent, TableLayout.LayoutParams.WrapContent); return tableRow; } }
杈呭姪绫综合
public class DynamicControl { public Button AddButton(Context context, string text, EventHandler clickAction = null) { var btn = new Button(context); btn.SetText(text, TextView.BufferType.Normal); if (clickAction != null) { btn.Click += clickAction; } return btn; } public TextView NewText(Context context, string str, Color? color = null) { var text = new TextView(context); if (color.HasValue) { text.SetTextColor(color.Value); } text.SetText(str, TextView.BufferType.Normal); return text; } }
The above is using C#+Xamarin to develop Android applications--dynamically adding controls Content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Active Directory with C#. Here we discuss the introduction and how Active Directory works in C# along with the syntax and example.

Guide to the Access Modifiers in C#. We have discussed the Introduction Types of Access Modifiers in C# along with examples and outputs.

Guide to Random Number Generator in C#. Here we discuss how Random Number Generator work, concept of pseudo-random and secure numbers.

Guide to C# Data Grid View. Here we discuss the examples of how a data grid view can be loaded and exported from the SQL database or an excel file.

Guide to C# StringReader. Here we discuss a brief overview on C# StringReader and its working along with different Examples and Code.

Guide to Patterns in C#. Here we discuss the introduction and top 3 types of Patterns in C# along with its examples and code implementation.

Guide to C# Serialization. Here we discuss the introduction, steps of C# serialization object, working, and example respectively.

Guide to C# StringWriter. Here we discuss a brief overview on C# StringWriter Class and its working along with different Examples and Codes.
