2

I'm trying to get to grips with the Monodroid in Visual Studio. Is there a way to use C# to dynamically create multiple controls for an android layout?

I'm used to ASP.NET and so would have thought something like the following would make sense- however with this being XML and not ASP I'm a little stuck.

PlaceHolder PlaceHolder1 = new PlaceHolder();

Label myLabel = new Label();
myLabel.Text = "some text";
myLabel.ID = "label ID";
PlaceHolder1.Controls.Add(myLabel);

etc.

Any suggestions for advice will be greatly appreciated.

Thanks all.

1 Answer 1

0

The equivalents for Placeholders are Layouts including:

  • LinearLayout -default orientation of horizontal
  • RelativeLayout
  • GridLayout
  • FrameLayout

There are plenty of tutorials for how to use these in XML - eg http://www.learn-android.com/2010/01/05/android-layout-tutorial/

And you can also manipulate these in code - using the ViewGroup Methods - http://developer.android.com/reference/android/view/ViewGroup.html - e.g, using AddView

You'll find plenty of java examples of this and they port very quickly to monodroid - eg create layout through code

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, this is most helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.