android.support.v5.app.Fragment or android.app.Fragment? -
im using android studio 1.0 rc1.
i have created mainactivity (tabbedactivity):
public class mainactivity extends actionbaractivity implements actionbar.tablistener
it imports:
... import android.support.v4.app.fragment; ...
so heres problem: ive made fragmentactivity:
public class blankfragment extends fragment {
this on imports:
now want this:
public fragment getitem(int position) { // getitem called instantiate fragment given page. // return placeholderfragment (defined static inner class below). switch (position){ case 0: return scoutlogfragment.newinstance("a","b"); case 1: return blankfragment.newinstance("a", "b"); case 2: return placeholderfragment.newinstance(position + 1); default: return placeholderfragment.newinstance(position + 1); } }
but tells me:
"required: import android.support.v4.app.fragment; found : de.example.local.scouttools.blankfragment"
if change main activity import android.app.fragment; t tells me return type of getitem(int position) wrong.
i dont why 1 imports android.app.fragment , other android.support.app.v4.fragment, how fix that?
it depends devices runs fragments.
support v4 used support library.
it can imported in build.gradle
compile 'com.android.support:support-v4:21.0.0'
if dont use support library devices android 3.0 or newer may use fragments.
if use support library devices @ least 2.1 can use fragments.
take care: if use support library app little big bigger in filesize.
make sure import proper fragment class support library. is
import android.support.v4.app.fragment;
if device impor actionbar need support library v7.
the import
import android.support.v7.app.actionbaractivity;
the required library can imported gradle with
compile 'com.android.support:appcompat-v7:21.0.0'
oh, , blankfragment seems import wrong classes. validate uses v4 fragment in blankfragment class aswell.
Comments
Post a Comment