5

Trying to make the Fragments example work on lower than 11 SDK, I get an error in

setListAdapter(new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_list_item_activated_1, Shakespeare.TITLES));

saying "simple_list_item_activated_1" cannot be resolved or is not a field". In import i have

import com.example.android.apis.R; 
import com.example.android.apis.Shakespeare;

What wrong is in here?

lomza
  • 9,412
  • 15
  • 70
  • 85

3 Answers3

4

That resource is new to API Level 11. If you want to use that resource on earlier versions of Android, copy it out of your SDK and into your project, then reference your project-local copy. Note that you may need to make other adjustments to this layout file, as I think it will refer to some new style attributes and such that do not exist in earlier versions of Android.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hmm, I found this resource in C:\android-sdk_r10-windows\android-sdk-windows\platforms\android-11\data\res\layout and copied it into my project's layout directory, and then it showed an error in it, in fron of " – lomza Mar 13 '11 at 13:26
  • @lomza: That was my point about having to "make other adjustments". :-) Here is another SO question related to this topic: http://stackoverflow.com/questions/5274982/compatibility-lib-fragments-activated-and-a-headache – CommonsWare Mar 13 '11 at 13:39
  • I have one more question. My Fragments app is working except showing the details when in portrait view. If I don't get any errors and the .java file is 99% OK, is it the AndroidManifest.xml file I have to edit in order to make my app work properly? Thank You! – lomza Mar 17 '11 at 09:40
0

You can follow below path in eclipse to import sample applications into your workspace:

File => New => Android => Android Sample Project

Here you should select android platform which you installed its sample e.g. Android 3.2.

Then select ApiDemos and click finish(below picture). Note: after creation of ApiDemos sample in your eclipse workspace you should left this project open so other projects inside workspace can refer it.

enter image description here

VSB
  • 9,825
  • 16
  • 72
  • 145
0

If you installed Samples through SDK MANAGER you can find it through samples directory of your android installation directory. e.g. in my computer Shakespeare implementation is located here:

C:\Program Files\Android\android-sdk\samples\android-13\ApiDemos\src\com\example\android\apis\Shakespeare.java

you can simply copy it to your source files folder.

VSB
  • 9,825
  • 16
  • 72
  • 145