This project which is provided in the samples of the Android SDK seems like a great entry point for a developer trying to get familiar with the Android environment quickly. This write-up will cover importing a sample from the Android SDK in the Android Studio.
- Multiple layouts
- Multiple densities
- Mock data
Installing the SDK examples
From the SDK Manager assure the SDK examples have been installed.
Once installed the files are typically in at
c:\Program Files (x86)\Android\android-studio\sdk\samples\android-19
The example we are looking for is AdapterTransition under the UI directory.
Copy the AdapterTransition directory to your projects directory (to preserve the source copy).
Establish a functional version
From the Android Studio ‘Import Project’
Navigate to the copy of AdapterTransition and select the build.gradle file and click OK.
Adding the missing strings
You will probably run into the following error. This is because there is no definition for ‘show_as_grid’, ‘show_as_list’, or ‘item_clicked’. The solution is to simply add those strings but the files may be read only so that must be addressed. I’ve captured the screens as they occurred to demonstrate the debugging process to get the project working.
Base on this error I can see @string/show_as_grid is missing.
Trying to add to the strings.xml file I ran into this. You can clear the ‘Read-Only’ status on each file as you make changes, or remove the ‘read-only’ attribute from the Windows File Explorer.
After adding a string it is important to ‘Save’ or ‘Rebuild’
After the Rebuild two more strings show up, ‘show_as_list’ and ‘item_clicked’.
One more rebuild and no errors. I can run up the example and see how it works.