Unable to use Fragments with Android Compatibility Package - android

In "Fragments for All", Xavier Ducrohet, Android SDK Tech Lead says Google releases an Android Compatibility Package by SDK Manager.
I've installed it, but, how can I use it now?
How can I integrate Android Compatibility Package in my project?

If you're using version 12 or later of the Eclipse Android support library, just right-click on your project, and choose Android Tools > Add Compatibility Library...

There is a .jar file called android-support-v4.jar in the directory {yoursdkpath}/extras/android/compatibility/v4/. Copy this into your libs folder in the root of your project and add the file to the build path in Eclipse.

Premier,
I followed the Fragments example on the Android Developers Blog to create a "backwards" compatible app using Fragments. In the article there is a brief mention of the Main activity that uses a layout with fragments.
The code for this activity is not interesting; it just calls setContentView() with the given layout:
What should be mentioned here is that this activity must derive from FragmentActivity and not Activity class. This threw me off for a while.
Good luck

Refer Using Fragment of Android Compatibility Package may help you

Check the "Step 2: Configuring the Build Path" Section here

This is easy with new Eclipse I downloaded. Provided you have all the paths for SDK etc setup correctly, Right click on Project -> Android tools-> and Hit "Add compatibility Library" it will add the JAR file

Related

Using serial for android library

I'm trying to implement this https://github.com/mik3y/usb-serial-for-android/blob/master/UsbSerialExamples/src/com/hoho/android/usbserial/examples/SerialConsoleActivity.java in my project but there is something wrong with this sample.
Line 121:
sDriver.setParameters(115200, 8, UsbSerialDriver.STOPBITS_1, UsbSerialDriver.PARITY_NONE);
Why I can't see this method setParameters()?
I had the same problem when I tried to use the example project. The problem I had was that I was using usb-serial-for-android-v010.jar that you can download from the git repository. I think it was created using an older version of the project and doesn't support some of the newer features like setParameters. If you downloaded the example project there should be a folder inside called UsbSerialLibrary. Import that into your IDE and add it to your build path: (Eclipse) Properties>Java Build Path>Projects>Add. This should let you use setParameters.
Also, the API was recently refactored so you may want to look at that.

Unresolved dependency error when creating a new project

This error appears when creating a new Android Application module in Android Studio using Fixed Tabs + Swipes for navigation.
It says:
The following dependencies were not resolvable. See your build.gradle
file for details. - com.android.support:appcompat-v7:18.0.0
I'm targeting Android 4.0+ devices. Why is the compatibility library involved? One workaround is to install this library using the Android SDK manager, but I'm concerned my app will actually use this compatibility library when there is no reason to. The ActionBar and fixed tab navigation should be built-in to the Android 4.0+ framework right?
This happened to me with IntelliJ Idea 13 Ultimate when creating new Gradle Module. I was working on the app that supports Froyo. I had to manually add support libraries to the SDK. After that I was able to build just fine. Here is the screenshot of Project Structure settings for SDK that I have:
As you can see, support for v4, v7 and v13 which were added manually. Those will be associated with Android API 19 Platform (in my case). When you create next new Gradle Module, you will still need to go to Project Structure to select the SDK under Project, but you will not need to add support libs again. Hope this helps.
I installed the compatibility library anyways. Something I didn't realize is that you can't create your first module by using File -> New Module. You have to use File -> Project Structure -> New Module for your first module. It's really unintuitive. After I did this, then everything worked.

How to resolve the error "No resource found that matches the given name" when adding library v7 AppCompat in Eclipse?

I have a project target to API Level 10 and i want to implement the new ActionBar support library.
After follow all the instrutions in the Support Library Setup, when adding the library to my project I came across with dozens of error messages like this:
android-support-v7-appcompat\res\values-v14\styles_base.xml:24: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.....
OK, i know that they are many answers to this question, but, after trying all the more obvious, i still could not solve the error.
I kept searching and found the cause, which is not so obvious, at least for newbies like me.
My intent is provide a full answer to help all those who are like me and do not master all the secrets of the Android development.
This is what you have to do for use the ActionBar support library correctly.
Follow the instructions in the Support Library Setup - Adding libraries with resources.
One thing that can bring some doubt is add the library to your aplicattion project:
(1) In the Project Explorer, right-click your project and select Properties.
(2) At the left pane select Android.
(3) At th bottom of the right pane click Add
(4) Select the library project android-support-v7-appcompat and click OK.
Click OK to close the properties window.
If you not get any of the errors I mentioned it´s all done.
However if you are like me, you dont´t followed the advice of Android team that suggests you always compile your source using the latest SDK, you get the error.
The error ocurrs because my Project Build Target was Android 2.3.3 and need to be at lest 3.0.
It was not immediately clear to me because of the fact that I'm specifically developing for Android 2.3.3 and I'm using support libraries.
OK, I hope this helps.
You should add that support library to your project. To add:
Right click on project, then go to :
properties > Java Build Path > Libraries
here Add External JARs...
add android-support-v7-appcompat.jar (path/to/sdk/extras\android\support\v7\appcompat\libs)
Additionally you also have to copy that jar to libs folder of your project, if it is not there automatically.
and you should use the #style/Theme.AppCompat theme for your application for support-v7 to be working
also keep one thing in mind you should change min sdk version to 11 if you want to support("android:windowActionBar")property in your project.

Adding supported libraries in android application

I'm a newbee in android platform. Im trying to create one appliccation in the latest version. but i want to run that app in the lowest versions.I just heared about using supported libraries along with the application.
I have some doubts about that
How we can add supported libraries in our application, from where we can download that?
when we develop using spported libraries .when we run on a lowest platform , which functionalities of the highest version we can use?
is highest versions UI is supported in lowest version?
give some example for adding the supported libraries..
Thanx in advance !
The Support Library is a quiet extending topic. I would suggest to read through it here. But here are some answeres to your questions.
Just Right Click on your project > Android Tools > Add Support
Library (With the little Android icon.)
What exactly is supported can be read here Using the v4 Library
APIs. It adds support for some of the most useful features of
later Android versions. Take a look at Fragments, Loaders and
ViewPagers.
If I understand your question correctly, there are some view you can
use with the support library, but if you want the Actionbar in 2.3
you need to use a library like ActionBarSherlock.
An example for adding the support library is a little hard, just do
what I wrote in 1. But here is a example of using the support
library with Fragments.
First import the support library classes:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
And then us them:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
// getSupportFragmentManager() is for getting the
// FragmentManager of the Support Library
// this is the only support library part
FragmentManager fm = getSupportFragmentManager();
// from here like a normal fragment, create the fragment
Fragment frag = ExampleFragment.instantiate(this, "ExampleFragmentName");
// start a fragment transaction
FragmentTransaction ft = fm.beginTransaction();
// add the fragment to the transaction
ft.add(R.id.content, frag);
// commit the fragment transaction
ft.commit();
}
I hope this is helpful.
See link from #Marko Niciforovic
Support library is as said mostly for the support of fragment and fragment transaction before Android 3.0
Simple and short answer is no. You would have to write your own Themes and Styles.
Eclipse --> Right click on project --> Android Tools --> Add support library
If it's not working, check that on the projects build path --> right click project --> build path --> configure build path in the tab order & export the "Android Private Libraries" or "*android-support-vx.jar" is exported (checkbox ticked).
Hope we could answer your questions.
I think supported lib is mostly used for fragments because they are added in 3.0. To use android support library you can download it directly from eclipse, check here http://developer.android.com/training/basics/fragments/support-lib.html, but mostly its something like this:
Eclipse -> Window -> Android SDK and AVD Manager -> Available Packages -> Android Support
http://developer.android.com/tools/extras/support-library.html
Downloading the Support Package
The Support Package is provided as a downloadable package from the Android SDK Manager. To install:
Launch the Android SDK Manager.
From Eclipse, you can select Window > Android SDK Manager. Or, launch SDK Manager.exe from the / directory (on Windows only) or android from the /tools/ directory.
Expand the Android Repository, check Android Support package and click Install selected.
Proceed to install the package.
When done, all files (including source code, samples, and the .jar files) are saved into the /extras/android/support/ directory. This directory contains each of the different support libraries, such as the library for API level 4 and up and the library for API level 13 and up, each named with the respective version (such as v4/).
Open Android SDK MAnager. Scroll down to Extras. Under Extras choose Android Support library and click install.
Setting Up a Project to Use a Library
In your Android project, create a directory named libs at the root of your project (next to src/, res/, etc.)
Locate the JAR file for the library you want to use and copy it into the libs/ directory.
For example, the library that supports API level 4 and up is located at /extras/android/support/v4/android-support-v4.jar.
Add the JAR to your project build path.
In Eclipse, right-click the JAR file in the Package Explorer, select Build Path > Add to Build Path.
Check the link below under the topic Using the v4 Library APIs
http://developer.android.com/tools/extras/support-library.html#Downloading
Don't start with the latest SDK all the time. Start with the minimum version may be ginger bread 2.3. Use ICS only if u want to add ICS specific items such as expandable widgets and all.

How to add javadoc for android to Netbeans

I just started using Net Beans. I am wanting to try my hand at developing android apps. I got the android sdk downloaded and everything is working well. I can create little apps and run them in the emulator. However, the intelisense popup for the android methods says that the Javadoc isn't found. Is there a way to add it?
The best way as below steps in NetBeans 7:
Tools --> Ant Libraries.
New library --> Name it Android.
Classpath --> Add JAR/Folder --> {SDK Folder}\platforms\android-16\android.jar
(in short find android.jar and use it's path, for me I'm using 16 version).
Javadoc --> Add ZIP/Folder --> {SDK Folder}\docs\references
(important note: you may get error in above step, so search will not work. To solve it, copy the file index.html inside [references folder] to a new file and called index-all.html. Then re-add the path in step 4).
Source: Here
Take a look at the Android Sources provided by adt-addons. This eclipse plugin will download all of the sources and attach them automatically.
If you aren't using Eclipse, you can still download the source zips from the jar at http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/plugins/
Extract the jar file and inside you'll find source zips for each platform revision. Attach these to your IDE.
Otherwise, you can check out the sources manually from git but this is a rather lengthy and arduous process to achieve the above.
You can download various javadocs from
http://www.jarvana.com/jarvana/browse/com/google/android/android/2.3.3/
Just drop the javadocs jar files to android-sdk-{macosx,windows,linux}/docs
Not sure what your setup is like, but the JavaDoc is stored in /docs/reference
For my setup I had to create a zip of that folder and add it as JavaDoc to the Android library.
If you use the nbandroidsupport plugin you can download the javadoc from Android SDK Manager, you can found the package in the latest android's API (in my case Android 5.1.1) the name of package is "Documentation for Android SDK".
Once you have installed the package restart your netbeans. In my case the javadoc is not showing sometimes pressing ctrl+space on the method therefore you can show the javadoc pressing ctrl+shift+space.
Note: this method applies to any API version.

Categories

Resources