2016-06-16 7 views
0

Ich habe untersucht, wie man UI-Elemente rein durch CodeSo fügen Sie UI-Elemente dynamisch in Android

Wie kann ich das tun?

RelativeLayout mainLayout = FindViewById<RelativeLayout>(Resource.Id.MainRelativeLayout); 
TextView newText = new TextView(this); 
newText.Text = "HEY THERE NEW TEXT MADE VIA CODE"; 
mainLayout.AddView(newText); 


// Set our view from the "main" layout resource 
SetContentView(Resource.Layout.Main); 
+0

I Xamarin verwende. Android – mrOak

Antwort

0

Es stellte sich heraus, dass Sie Ihren Code platzieren müssen nach

/ Set our view from the "main" layout resource 
SetContentView(Resource.Layout.Main); 

RelativeLayout mainLayout = FindViewById<RelativeLayout>(Resource.Id.MainRelativeLayout); 
TextView newText = new TextView(this); 
newText.Text = "HEY THERE NEW TEXT MADE VIA CODE"; 
mainLayout.AddView(newText); 

oh den Inhalt Ansicht einstellen und Sie müssen den Typ unter findViewById < TYPE angeben>

Verwandte Themen