백엔드 개발 C#.Net 튜토리얼 C# + Xamarin을 사용하여 Android 애플리케이션 개발 - 동적으로 컨트롤 추가

C# + Xamarin을 사용하여 Android 애플리케이션 개발 - 동적으로 컨트롤 추가

Mar 01, 2017 am 10:30 AM

C# + Xamarin을 사용하여 Android 애플리케이션 개발 - 동적으로 컨트롤 추가

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

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;

        }

    }

로그인 후 복사

杈呭姪绫 Guy

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

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으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

C#을 사용한 Active Directory C#을 사용한 Active Directory Sep 03, 2024 pm 03:33 PM

C#을 사용한 Active Directory

C#의 액세스 한정자 C#의 액세스 한정자 Sep 03, 2024 pm 03:24 PM

C#의 액세스 한정자

C#의 난수 생성기 C#의 난수 생성기 Sep 03, 2024 pm 03:34 PM

C#의 난수 생성기

C# 데이터 그리드 보기 C# 데이터 그리드 보기 Sep 03, 2024 pm 03:32 PM

C# 데이터 그리드 보기

C#의 패턴 C#의 패턴 Sep 03, 2024 pm 03:33 PM

C#의 패턴

C# 스트링리더 C# 스트링리더 Sep 03, 2024 pm 03:23 PM

C# 스트링리더

C# 스트링라이터 C# 스트링라이터 Sep 03, 2024 pm 03:23 PM

C# 스트링라이터

C#의 BinaryWriter C#의 BinaryWriter Sep 03, 2024 pm 03:22 PM

C#의 BinaryWriter

See all articles