Re: Help to implement TabNavigation

250 views
Skip to first unread message
Message has been deleted

Jonathan Steele

unread,
Mar 11, 2012, 12:31:20 PM3/11/12
to actionba...@googlegroups.com
you have to drop using Activity for ActionBar Tab and use Fragment.

Here mine Tabbed Activity that will help you
https://github.com/iNoles/Android/blob/master/AndroidNolesCore/src/activities/AbstractTabbedActivity.java

On Sunday, March 11, 2012 7:29:16 AM UTC-4, Jose Miguel Linares Sillero wrote:
Hi all, i'm starting to develop on android and found this library by chance, i have to say that i loved from the beginning and it seems incredible. Now i only need to start working with it little by little hehe.  (totally noob xD)

I am having problems implementing and adapting the sample of TabNavigation. What i'm trying to do is a TabNavigation, showing different Activitys with its contents. Without SherlockActionBar library, i have it so:
(like tutorial tab of developer.android
     
        intent = new Intent().setClass(this, Activity1.class);
        spec = tabHost.newTabSpec("Activity 1").setIndicator("Activity 1",
        res.getDrawable(R.drawable.ic_tab_info))
        .setContent(intent);
        tabHost.addTab(spec);

Now, looking at the source from the sample of TabNavigation of SherlockActionBar:

I put the Tabs:
                     ActionBar.Tab tab1 = getSupportActionBar().newTab();
                     tab1.setText("Activity 1");
                     tab1.setTabListener(this);
                     getSupportActionBar().addTab(tab1);

and in function
onTabSelected, as an issue here, i put:

                     int iPosition = tab.getPosition();
                     String tabText = tab.getText().toString();

                     switch(iPosition)
                     {
                            case 0:
                                        Intent intent = new Intent(this, Activity1.class);
                                        startActivity(intent);
                                        break;
                     (...)

If I do this, the Activity is fully open and i lose the Tab menu. :(

I think my problem is just being a nooooooob, i think the problem is how to declare the Activitys. With the first method are Activitys normal, but with SherlockActionBar i think i need to declare them in a particular way... but honestly i can not think how to put it :(
Message has been deleted
Message has been deleted

Jonathan Steele

unread,
Mar 12, 2012, 3:05:03 PM3/12/12
to actionba...@googlegroups.com
Try file that I uploaded.

On Monday, March 12, 2012 10:49:57 AM UTC-4, Jose Miguel Linares Sillero wrote:
Sorry Jonathan... you will kill me but after a whole day just trying it and having faults... i quit and have to ask you again for help. All about of the fragments is new to me and driving me crazy. Right now I'm trying that each Tab invoke a SherlockFragment with its own layout.xml.

First the main with Tabs, as the sample of TabNavigation of JakeWharton. And then "onTabSelected":

        int iPosition = tab.getPosition();
       
        switch(iPosition)
        {
            case 0:
                    mSelected.setText("Selected: " + tab.getText());
                    break;
            case 1:
                    mSelected.setText("Selected: " + tab.getText());
                    SherlockFragment fragment1 = new SherlockFragment();
                    fragment1.getFragmentManager().findFragmentById(R.id.fragmentA);
                    transaction.replace(R.id.content_frame, fragment1, null);
                  
                    break;
        }

These are the layouts:

fragment_layer.xml
   
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent"
         />

and fragments_a.xml

<fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fragmentA"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.test.FragmentA" >
       
</fragment>
TabSherlockMain.java
Message has been deleted

Bas Verhoog

unread,
Mar 15, 2012, 10:06:39 AM3/15/12
to actionba...@googlegroups.com
Hello everyone,

I too am having problems implementing the FragmentTabsPager. Can anyone help me with that? If so, I'll upload the files I'm using :).

Regards,

Bas
Reply all
Reply to author
Forward
0 new messages