Loading...

Thursday, 9 August 2012

Set TabActivity (Android)

package com.test.android;

import com.test.android.R;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class TestTab extends TabActivity{
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fuel);
       
        TabHost tabHost = getTabHost();
       
        TabSpec spec1=tabHost.newTabSpec("");
        sp1.setIndicator("",getResources().getDrawable(R.drawable.logo));
        Intent in1=new Intent(this, TestTab1.class);
        sp1.setContent(in1);
       
        TabSpec sp2=tabHost.newTabSpec("");
        sp2.setIndicator("",getResources().getDrawable(R.drawable.logo));
        Intent in2=new Intent(this, TestTab2.class);
        sp2.setContent(in2);

        TabSpec sp3=tabHost.newTabSpec("");
        sp3.setIndicator("",getResources().getDrawable(R.drawable.logo));
        Intent in3=new Intent(this, TestTab3.class);
        sp3.setContent(in3);

       
        tabHost.addTab(sp1);
        tabHost.addTab(sp2);
        tabHost.addTab(sp3);
       
    }
}
// make other class TestTab1, TestTab2 and TestTab3

// class TestTab1
package com.test.android;

public class TestTab1 extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_2);
        // post code here
    }
}
// class TestTab2
package com.test.android;

public class TestTab2 extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_2);
        // post code here
    }
}
// class TestTab3
package com.test.android;

public class TestTab3 extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_2);
        // post code here       
    }
}

No comments:

Post a Comment