0

I have an app that opens various sub activies. Whenever the mobile is on API level 11+, I would like to show a button to open an activity that opens a calendar.

However, when e.g. designing the activity XML, I get error:

View requires API level 11 (current min is 8): activity_calendar.xml

Is there any way to markup xml/code files that they should only be avilable/compile-for API level 11... And then write code that based API-level includes the option to show/open the calanedar activity requiring aPI level 11?

This is a general question although in my case, it is caused by wanting to use CalendarView. (I know there are some Apache version 2.0 license calendar alternatives which I am currently considering.)

Tom
  • 3,457
  • 8
  • 64
  • 119
  • 1
    You always have the option of creating xml resources(drawables, layouts etc) based on API levels. In code however you'd have to test on which version you are and use/not use the new APIs. – user Mar 16 '13 at 09:37
  • (I have already placed the XML file in "example/res/layout-v11", but I stil get the same error.) – Tom Mar 16 '13 at 11:12

1 Answers1

3

For code:

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD) { 
    // do stuff for newer than Gingerbread
}

For XML

/res/layout-v8

Change the versions as you need.

Simon
  • 14,029
  • 6
  • 43
  • 60
  • (I have already placed the XML file in "example/res/layout-v11", but I stil get the same error.) – Tom Mar 16 '13 at 11:12