The problem it solved, in this discussion, I gave the solution of the problem: Solution to the problem
I created a project with Android Studio 1.1.
With support by the API 19 to 22
But now I'm having problems with compatibility libraries:
import android.support.v4.app.Fragment;
import android.app.Fragment;
I created a Navigation Drawer Activity as a base.
I created following a fragment blank.
I simply had to call this new fragment in my Navigation Drawer, or rather in my ActivityMain in onNavigationDrawerItemSelected method, but I have a problem with the libraries.
In my ActivityMain, libraries are: android.support.v4.app.Fragment;
while in the new Fragment Blank I created, the libraries are: import android.app.Fragment;
And of course when I try to interact with objects of type Fragment to maneuver the switch case, I have compatibility problems? between:
import android.app.Fragment;
import android.support.v4.app.Fragment;
What causes all this confusion?
I state that I have done nothing, if not simply create classes.
Where am I wrong?
Related
I'm having a problem with calling me fragments when using FragmentPageAdapter in a swipe-function
The problem in images:
http://www.afbeeldinguploaden.nl/photo/view/90082/sxP3Rre
http://www.afbeeldinguploaden.nl/photo/view/90083/EefjiS4q
Anyone can help me with this or what can I do?
Your HomeFragment needs to extend android.support.v4.app.Fragment, so that means you need to import:
import android.support.v4.app.Fragment;
I'm trying to replace the ActionBar of my app with a Toolbar but I can't because I can't use setSupportActionBar(). It says "setSupportActionBar() is undefined for the type MainActivity" even if MainActivity extends ActionBarActivity.
I don't know what to do, any help? Do you need me to post my code?
EDIT:
Now the code works but my app crashes on start and it says: "Attempt to invoke virtual method getTitle()". What do I miss?
EDIT2:
Everything works I forgot I had a Fragment and because of that it gave me nullPointer
Now use :
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
setSupportActionBar(toolbar);
XML :
android.support.v7.widget.Toolbar
Extends :
public class MainActivity extends AppCompatActivity
Without code, my only recommendation, is making sure your import statement is as follows:
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
Also make sure in your XML files that you are using
<android.support.v7.widget.Toolbar
As your toolbar tag
import androidx.appcompat.app.AppCompatActivity;
import this class instead of:
import android.support.v7.widget.Toolbar;
or
import android.widget.Toolbar;
The newer version requires the android class
How can you show two fragments side by side?
I have tried FragmentTransaction.replace(R.id.fragmentcontainer, myFragment),
where myFragment inflates a layout which contains two fragments that reference to my other fragment classes.
But this gives me an error saying "myFragment cannot be cast to android.support.v4.app.Fragment.
Any help would be appreciated
check your import statements
Replace these statements
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
with these statements
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction
I trying to extends my main class from TabActivity ... I wrote the code as bellow :
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class AndroidTabAndListView extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
.
.
.
.
.
}
but I have a worning that the type TabActivity is deprecated !!!!!
Have any one any Idea about this ???
thank you in advance , Fadel
Please see the official document.
This class was deprecated in API level 13. New applications should use
Fragments instead of this class; to continue to run on older devices,
you can use the v4 support library which provides a version of the
Fragment API that is compatible down to DONUT.
See also:
"The type TabActivity is deprecated" For app tab
https://stackoverflow.com/questions/12600207/the-type-tabactivity-is-deprecated-help-to-use-in-older-device
Android: TabActivity deprecated, use Fragments?
Or if you have a more specific question, you can add more info.
I have been successfully using HoloEverywhere's PreferenceActivity for a while. I am now importing the SlidingMenu library and has been going well so far until I extended SlidingMenu's SlidingPreferenceActivity:
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingPreferenceActivity;
public class SettingsActivity extends SlidingPreferenceActivity{
...
and
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import org.holoeverywhere.preference.PreferenceActivity;
public class SlidingPreferenceActivity extends PreferenceActivity implements
SlidingActivityBase {
...
In my SettingsActivity I load some Header's to show the top level categories.
My problem is now onHeaderClick() is no longer working. I trace it all the way through and cannot find the error. Following the stack trace I see HoloEverywhere ends up making an Intent it eventually passes to the Android Activity, but I don't see anything that is obviously wrong.
What about the SlidingMenu Library could cause Fragments to stop working in a PreferenceActivity?
Turns out my problem had nothing to do with SlidingMenu. In my manifest I set all my Activitys to be singleInstance, so that I am not making multiple of the same Activity when I am navigating between them using the SlidingMenu. This was preventing the Intent that was created by PreferenceActivity when the Header was clicked from recreating the activity with the given fragment.
I removed the singleInstance reference for now and everything is working.