Reputation: 11816
Im just trying out Andorid Xamarin in VS 2012. Im doing their Hello World tutorial but I encountered a problem. I have declared my main layout resources in this way:
In my activity, whenever i try to find the resource through their id, it just returns null.
Both aButton
and aLabel
are null. I dont know what is the cause of this problem. Can you help me please? Thanks.
PS: I am attaching also my resource designer class. My objects are declared there (wink).
EDIT: This is the corrected code.
Upvotes: 1
Views: 1379
Reputation: 2183
You are missing a call to SetContentView
in your OnCreate
method.
var layout = LayoutInflater.Inflate(Resource.Id.Main);
SetContentView(layout);
The first line creates a new view from the resource Main.axml. The second line sets the content view of the activity so it has something to actually display and hence subsequent calls to FindViewById<T>()
will be able to find the views.
Upvotes: 3