We provide complete mobile and web apps development solutions

Tuesday, January 22, 2013

Fragments- ActionBar android

public class StartActivity extends Activity {
    public static Context appContext;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        appContext = getApplicationContext();

          ActionBar actionbar = getActionBar();
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
       
        ActionBar.Tab PlayerTab = actionbar.newTab().setText("SONGS");
        ActionBar.Tab StationsTab = actionbar.newTab().setText("VIDEOS");


       ActionBar.Tab PhotosTab = actionbar.newTab().setText("PHOTOS");       
        Fragment sFragment = new SongsFragment();
        Fragment vFragment = new VideosFragment();

        sTab.setTabListener(new MyTabsListener(sFragment));
        vTab.setTabListener(new MyTabsListener(vFragment));

        actionbar.addTab(sTab);
        actionbar.addTab(vTab);

}



 

SongsFragment.java

public class SongsFragment extends Fragment {
   
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.songsfragment, container, false);
    }
   
}







public class VideosFragment extends Fragment {
   
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.videosfragment, container, false);
    }





PhotosFragment.java



 
public class PhotosFragment extends Fragment {
   
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.photosfragment, container, false);
    }
   
}



xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
   android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="center">
    <LinearLayout
        android:id="@+id/fragment_tab"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

 </LinearLayout>
</LinearLayout>
 





0 coment�rios:

Post a Comment

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts