使用C# + Xamarin開發Android應用程式-- 動態新增控件
使用C# + Xamarin开发Android应用-- 动态添加控件
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; } }
登入後複製
以上就是使用C# + Xamarin开发Android应用-- 动态添加控件的内容,更多相关内容请关注PHP中文网(www.php.cn)!
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
<🎜>:種植花園 - 完整的突變指南
3 週前
By DDD
<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
如何修復KB5055612無法在Windows 10中安裝?
3 週前
By DDD
北端:融合系統,解釋
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前
By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

使用 C# 的 Active Directory 指南。在這裡,我們討論 Active Directory 在 C# 中的介紹和工作原理以及語法和範例。

多線程和異步的區別在於,多線程同時執行多個線程,而異步在不阻塞當前線程的情況下執行操作。多線程用於計算密集型任務,而異步用於用戶交互操作。多線程的優勢是提高計算性能,異步的優勢是不阻塞 UI 線程。選擇多線程還是異步取決於任務性質:計算密集型任務使用多線程,與外部資源交互且需要保持 UI 響應的任務使用異步。

可以採用多種方法修改 XML 格式:使用文本編輯器(如 Notepad )進行手工編輯;使用在線或桌面 XML 格式化工具(如 XMLbeautifier)進行自動格式化;使用 XML 轉換工具(如 XSLT)定義轉換規則;或者使用編程語言(如 Python)進行解析和操作。修改時需謹慎,並備份原始文件。
