Android SDK Fragment Support - android

Ok i'm just starting to get into Android programming now, and I'm following the android "TabActivity" tutorial: http://developer.android.com/reference/android/app/TabActivity.html.
Everythings working but it can't seem to find some of the support classes, see the code below that is generating the errors.
mTabManager.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class,null);
For FragmentStackSupport/LoaderCursorSupport/LoaderCustomSupport/LoaderThrottleSupport, it says for all of them cannot be resolved to a type. I've added the latest support library to a folder in the root directory named "libs" and also coppied it into "C:/Eclipse/v4/" directory. My import files are:
import java.util.HashMap;
import android.R;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.TabHost;
import cowdawg.hello_tab.namespace.R.layout;
import cowdawg.hello_tab.namespace.R.id;
Could someone please offer me some advice on how to solve this, thanks :).

It's probably because the following classes are not part of the standard Android API (or the support library), but only exist in the support demos sample code for demonstration purposes:
FragmentStackSupport.CountingFragment
LoaderCursorSupport.CursorLoaderListFragment
LoaderCustomSupport.AppListFragment
LoaderThrottleSupport.ThrottledLoaderListFragment
You will need to add these classes to your own project in order to be able to use them. Here you can find the source files under the subsection 'Files'.
FragmentStackSupport
LoaderCursorSupport
LoaderCustomSupport
LoaderThrottleSupport

On Eclipse IDE: Select your project and then right click on the project -> Android Tools -> Add Support Library.
Required support library will be added on your project build path. You will found this library jar under Java Build Path -> Libraries tab -> Android Dependencies.
Enjoy exploring!

Have you added the library to your build path? Right click on the jar in eclipse -> Build Path -> Add to Build Path.

Try adding by right clicking on the project and opening properties window

Instead of these missing classes you can create your own by subclassing Fragment class (or its subclasses like DialogFragment, ListFragment etc). More info is provided by Android here.

Related

android : navigation drawer and upgrading libraries methodology

Im following headfirst methodology to learn to code in androidstudio.
they provide some code for building a simple navigation drawer app.
in order to be compatible with previous android version, they advise to import :
import android.content.Intent;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
but in my last version of android studio this doesnt work : some of them are greyed and alt+enter does not import the correct library when i put the java code provided by my methodology.
so i replaced a few imports with the newer versions. for example :
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.ActionBarDrawerToggle ;
import android.widget.Toolbar;
however, i did not find anything for to import "NavigationView" and com.google.android.material.navigation.NavigationV iew is grayed when i try to import it.
So my question is basic: how do i know which lib to import when android studio does not suggest anything with alt+enter and when the libraries have evolved? the question could be asked for many programs i guess ..is there a standard methodology to upgrade the code?
You first need to include your dependencies in your build.gradle (app) file.
For example, your NavigationView is a part of Google's Material library. This library does not come included in Android SDK when you create the project and therefore you need to add the library under 'dependencies' in your build.gradle (app) file in order to use it:
dependencies {
implementation 'com.google.android.material:material:1.3.0-alpha01'
}
This way, upon the build of the project, Gradle will download the library and include it in your project so you can use the Material components. You can usually find the gradle dependency you need to include with a quick Google search.
Another thing to note is that the legacy support libraries have been replaced with AndroidX as you can read here:
https://developer.android.com/topic/libraries/support-library
https://developer.android.com/jetpack/androidx
And you can find the full list of AndroidX support libraries in here:
https://developer.android.com/jetpack/androidx/explorer

Why used import statement is specified as "unused import statement" in Android Studio?

I'm using Android Studio and build as "Generate Signed APK...". And I faced the error, "Unused import statement" like following.
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity; // <- specified as unused ERROR
import android.support.v4.app.FragmentManager; // <- specified as unused ERROR
import android.support.v4.view.ViewPager; // <- specified as unused ERROR
import android.util.Log;
public class Main extends FragmentActivity {
...
}
But I can easily see FragmentActivity is used in code. How can I fix it? This error happens all over my codes...
This is because you have "Optimize imports on the fly" enabled, which automatically removes unused imports. You likely also have "Add unambiguous imports on the fly" selected, which automatically adds imports you need. The solution is to write the code first, and watch your imports be added automatically, and manually add any ambiguous ones, as they become needed.
https://www.jetbrains.com/idea/help/creating-and-optimizing-imports.html?search=optim
In the event this does not work for you, or if you simply prefer to enter your own import statements, then simply disable the features in settings > Editor > Auto Import.
When I updated the android studio to 3.3.1 I go this error.
Solved it by updating the libraries and compileSdkVersion to the latest version that is 27. Hope it will help someone else.
I meet the problem in the Android studio 3.2.1. Invalidate and delete ./idea does not work. It disappear when I upgrade 3.4.1.

How to resolve import android.support.v7.internal.widget.ListPopupWindow?

I was trying to use the snippet from 2nd answer of the following post:
How do you turn off share history when using ShareActionProvider?
Which can be dowloaded from here and after adding ActivityChooserView.java along with other files to my project, I cannot resolve:
import android.support.v7.internal.widget.ListPopupWindow;
Import of android.support.v7.appcompat does not give any errors.
Where can I find android.support.v7.internal.widget.ListPopupWindow class?
I googled it and found nothing :)
I am compiling for android v23 and using appcompat.v7 of the same version.
As you can see here the package name is android.support.v7.widget, so the correct import is:
import android.support.v7.widget.ListPopupWindow;
ListPopupWindow was moved from android.support.v7.internal.widget to android.support.v7.widget in v7 appcompat library v21.0.0.
To fix the issue change the import to the updated one.

eclipse can't find android.support.v4.widget.SwipeRefreshLayout

Even after clicking on Add Support Library and choosing version 19, eclipse still can't find android.support.v4.widget.SwipeRefreshLayout. Does anyone know how to get this to work? I am using
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
I am working on a mac mavericks computer with Juno.
update: import section
import java.util.Observer;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.support.v4.widget.SwipeRefreshLayout;//red underline
Update
By the way, I don't know if this matters: this is an Appengine Connected Android Project, which I build using Google-Eclipse-Plugin
Update 3:
It's looking like the Android Support Library 19.1.0 is not available through the SDK Manager. How else might I obtain it?
It was difficult to update the support library to version 19.1 so i downloaded it manually from https://dl-ssl.google.com/android/repository/support_r19.1.zip and added the jar to my build path manually. works for me. I dont know why the 19 update shows instead of 19.1.0
So it turns out the library is in the following location
/android-sdk-macosx/extras/android/m2repository/com/android/support/support-v4/19.1.0
As opposed to the usual
/android-sdk-macosx/extras/android/support
Also I had to restart eclipse and go to Android SDK Manager over and over and over, until the 19.1.0 version shows up.
I hope this saves someone else some trouble.
The SDK Manager update Android Support Library to 19.1.0.
But when you use Android Tools > Add Support Library, eclipse update Android Support Library to 19.0. I think this is a bug. Copy Android Support Library 19.1.0 to libs folder manually.
It looks as if you don't have the android-support-v4.jar in Java Build Path. Add it from the android-support-v7-appcompat.
For some reason, even though you may include v4 support library or you may have v7-appcompat included in your project, you may not be able to import SwipeRefreshLayout.
You need to make sure that
you change the target=android-19 to target=android-22(It should be anything greater that 19) and
manually import : import android.support.v4.widget.SwipeRefreshLayout; in your activity which will resolve the import related issue.
I had the same problem with old project. But when I create new project, Eclipse can find this import.
It's a problem with updating support library from eclipse: https://code.google.com/p/android/issues/detail?id=67991
Just update it by starting Android SDK manager manually and add new v4 lib to your project.
Thanks for tehnolog's tips.
Update to 19.1 by follow above link -> create new project and import android.support.v4 library -> simply copy android.support.v4.jar to old project's libs folder, Add To BuildPath. SwipeRefreshLayout will appear :D
In androidx, add
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
inorder to use SwipeRefreshLayout

The import org.ksoap2.transport.HttpTransportSE cannot be resolved

I downloaded ksoap2 from this link:
after importing the downloaded .jar file into an Android project in Eclipse, I got import error for only the first import line (HttpTransportSE). I searched but nobody else has had/posted this issue. How could this be? thanks!
import org.ksoap2.transport.HttpTransportSE; //ERROR:The import org.ksoap2.transport.HttpTransportSE cannot be resolved
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
You've downloaded the J2ME package, but HttpTransportSE is part of the J2SE jar file.
Shouldn't ksoap2-j2se-full-2.1.2.jar work just fine with Android?
Use this library its specific for android and it worked for me (Ksoap2-j2se-full didn't work for me as well)
http://code.google.com/p/ksoap2-android/
You should use ksoap2-android-assembly-2.6.3-jar-with-dependencies.jar file.
visit http://code.google.com/p/ksoap2-android/wiki/HowToUse?tm=2
You will Have to add it to Library. (I am using Android Studio)
Right click the library file in the Android Studio(shown under project_name/app/libs/ -> there will an option "Add As Library",
select that
Then A dialogue box will appear where you will have to Select the Module
Thats IT! :)

Categories

Resources