So, I'm trying to put together some fragments. I have a TabActivity extending FragmentActivity. Inside the TabActivity i have 4 tabs that extend Fragments(android.support.v4.app.Fragment). Im trying to switch between fragments within one tab. I've looked at most solutions that are here on Stack Overflow, however none of them are working for me.
I also tried removeing the parent view and that doesn't seem to work either.
This is the code where im trying to change between fragments, however I always just get the background, not the layout that is in the xml. This is in a static class that extends Fragment:
protected void updateResultsInUi() {
if(verified){
// Create new fragment and transaction
Fragment newFragment = new All_media();
android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.homeScreenParent, newFragment, "mediaScreen");
transaction.commit();
}
else{
alert("Oops!", "");
}
}
This is the xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/allmedialayout">
<Button
android:id="@+id/buffon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/tocreatecity"
android:layout_below="@+id/camera_button"
android:layout_marginTop="30dp"
android:text="upload" />
<Button
android:id="@+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/tocreatecity"
android:layout_below="@+id/tocreatecity"
android:layout_marginTop="75dp"
android:text="camera" />
<Button
android:id="@+id/blog_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/buffon"
android:layout_alignRight="@+id/buffon"
android:layout_below="@+id/buffon"
android:layout_marginTop="22dp"
android:text="blog!" />
<Button
android:id="@+id/tocreatecity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="createcity" />
Can anyone tell me what im missing?
you can get the my demo of tab using fragment from here.