Skip to content

Instantly share code, notes, and snippets.

@patridge
Created February 17, 2015 15:38
Show Gist options
  • Save patridge/2ca7e309cd53716fb384 to your computer and use it in GitHub Desktop.
Save patridge/2ca7e309cd53716fb384 to your computer and use it in GitHub Desktop.
Android: what ID is that thing?
// I had to use this to debug why `OnOptionsItemSelected` wasn't triggering for an ActionBar home tap.
// Turns out, `Resource.Id.home` and `Resource.Id.homeAsUp` are not related to `Android.Resource.Id.Home`.
var projectIdType = typeof(Resource.Id);
foreach (var field in projectIdType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)) {
if (item.ItemId == (int)field.GetValue(null)) {
Console.WriteLine("{0}: {1}", field.Name, item.ItemId);
}
}
var androidIdType = typeof(Android.Resource.Id);
foreach (var field in androidIdType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)) {
if (item.ItemId == (int)field.GetValue(null)) {
Console.WriteLine("{0}: {1}", field.Name, item.ItemId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment