0

I have came across a very strange problem, i am using Pager in android to navigate between different screens through fragments in android. also i am using another fragment class to create Layouts automatically in a grid,

for fragment 1, where i have used the pager and pageradapter i am using these imports

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager; 

for the other fragment which i am using to populate images in a non linear Grid, i am using this import

import android.app.Fragment;

The issue is:

By using this import i am unable to add my fragments into the pageradapter. it keeps on giving me error.

 private List<Fragment> getFragments(){
            List<Fragment> fList = new ArrayList<Fragment>();

            fList.add(MyFragment.newInstance("Tv Shows"));
            fList.add(MyFragment.newInstance("Movies"));
            fList.add(MyFragment.newInstance("Music Videos"));

            return fList;
        }

also i cannot initialize my pageadapter

pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);

it gives me error on this line to.

My Question is:

what is difference between the two imports

import android.support.v4.app.Fragment;

and

import android.app.Fragment;

is there any solution to the problem, ?

Hassaan Rabbani
  • 2,469
  • 5
  • 30
  • 55

1 Answers1

1
 `import android.app.Fragment` 

requires minimum API level your app requires is 11 or higher. to use in in application with API less than 11 you need to use support library. when using support library you should use

import android.support.v4.app.Fragment;
null pointer
  • 5,874
  • 4
  • 36
  • 66
  • what is the link between pageradapter and import android.app.Fragment` as it does not work with this one, but it works fine with import android.support.v4.app.Fragment; – Hassaan Rabbani Jan 31 '14 at 07:21
  • because the parameter of android.support.v4.app.FragmentPagerAdapter pageradapter is android.support.v4.app.Fragment and not android.app.Fragment refer this http://stackoverflow.com/questions/17553374/android-app-fragments-vs-android-support-v4-app-using-viewpager – null pointer Jan 31 '14 at 07:31