如何从android中的其他活动调用特定活动的Tab

时间:2013-10-17 11:47:16

标签: android android-intent android-tabhost

我创建了两个tabs.Tab A和Tab B.从标签A,我导航到新活动说C.从C如何导航到特定活动的标签A.当我尝试时,它正在打开新的活动,我无法调用选项卡中的内容。请帮助我。

public class TabsActivity extends TabActivity {
String Activity;
Intent i;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabs);


    TabHost tabHost = getTabHost();

    // Tab for Photos
    TabSpec photospec = tabHost.newTabSpec("Tab A");
    // setting Title and Icon for the Tab
    photospec.setIndicator("Tab A");
    Intent photosIntent = new Intent(this, A.class);
    photospec.setContent(photosIntent);

    // Tab for Songs

    TabSpec songspec = tabHost.newTabSpec("Tab B");        
    songspec.setIndicator("Tab B");

    Intent songsIntent = new Intent(this, B.class);
    songspec.setContent(songsIntent);

    // Tab for Videos


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

}

在使用按钮的活动中,我正在转移到另一个活动......例如:NewActivity

在NewActivity中,如何切换回选项卡中的A。

NewActivity.java

public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(ListActivity.this,
         listsearchbutton = (Button) findViewById(R.id.listfilter);
        listsearchbutton.setOnClickListener(new View.OnClickListener() {

            @Override
                        TabsActivity.class);
                intent.putExtra("Activity", "A");
            //i dont know where to use getIntent in TabsActivity to call A activity
                startActivity(intent);
            }

        });

提前致谢。

2 个答案:

答案 0 :(得分:0)

替换它,

intent.putExtra("Activity", "A");
            //i dont know where to use getIntent in TabsActivity to call A activity
                startActivity(intent);

对此,

  finish();

答案 1 :(得分:0)

点击按钮

即可使用Activityname.this.finish();