0

I have tab activity with third tab

TabMainActivity

public class TabMainActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TabHost tabHost = getTabHost();

    Intent it=getIntent();
    int num_tab=it.getIntExtra("num_tab", 0);
    // Tab1
    TabSpec photospec = tabHost.newTabSpec("Tab1");
    // setting Title and Icon for the Tab
    photospec.setIndicator("Tab1", getResources().getDrawable(R.drawable.icon_photos_tab));
    Intent photosIntent = new Intent(this, PhotosActivity.class);
    photospec.setContent(photosIntent);

    // Tab2
    TabSpec songspec = tabHost.newTabSpec("Tab2");       
    songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
    Intent songsIntent = new Intent(this, SongsActivity.class);
    songspec.setContent(songsIntent);

    // Tab3
    TabSpec videospec = tabHost.newTabSpec("Tab3");
    videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
    Intent videosIntent = new Intent(this, VideosActivity.class);
    videospec.setContent(videosIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(photospec); // Adding photos tab
    tabHost.addTab(songspec); // Adding songs tab
    tabHost.addTab(videospec); // Adding videos tab

    tabHost.setCurrentTab(num_tab);
}

}

Tab1: Activity1.java

public class Activity1 extends Activity {

@Override
public void onCreate(Bundle circle)
{
    super.onCreate(circle);
    setContentView(R.layout.layout1);
    Toast.makeText(getBaseContext(), "This is tab1",Toast.LENGTH_LONG).show();
}

}

Tab2: Activity2.java

public class Activity2 extends Activity {

@Override
public void onCreate(Bundle circle)
{
    super.onCreate(circle);
    setContentView(R.layout.layout1);       
}

}

Tab3: Activity3.java

public class Activity3 extends Activity {

@Override
public void onCreate(Bundle circle)
{
    super.onCreate(circle);
    setContentView(R.layout.layout1);
            Button button3=(Button)findViewbyId(R.id.button3);
            button3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Activity3.this.finish();
            Intent it=new Intent(Activity3.this,TabMainActivity.class);
            it.putExtra("num_tab",2);
            startActivity(it);
        }
    });
}

}

Now,if in tab3 i click button3..It always operations codes in tab1(display toast as code)..then open again tab3.I only want to open again tab3 but don't operation codes in tab1.. How must i do?

4

1 回答 1

0

您可以尝试在“prepare()”而不是“onCreate()”中添加选项卡,但仍然在“onCreate()”中设置当前选项卡。

于 2013-05-27T05:21:47.263 回答