English 中文(简体)
• 如何将不同的活动称作同一个表格
原标题:How to call different activity on same tab

I need to implement tabs in my project.i have a layout, in which i have two tabs and a button. For two tabs,I have two activities and button calling different activity. the thing is I am showing result of button on first tab. now what i want is,if i press to first tab, first tab intent should be shown. or if i change tabs, tab s corresponding intent should be shown.

我尝试了以下法典,但在点击纽顿之后,每点击表1时,都显示纽芬兰的意图。

public class TabLayoutUsingTabChangeEventActivity extends TabActivity {

        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);                
            final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
            final TabHost.TabSpec sp1 = tabHost.newTabSpec("TAB1");
            TabHost.TabSpec sp2 = tabHost.newTabSpec("TAB2");

            //Creating First Tab
            Intent intent1 = new Intent(this, Tab1Activity.class);
            sp1.setIndicator("TAB1").setContent(intent1);
            tabHost.addTab(sp1);

            //Creating Second Tab 
            Intent intent2 = new Intent(this, Tab2Activity.class);
            sp2.setIndicator("TAB2").setContent(intent2);
            tabHost.addTab(sp2);               

            //Tab Changed Event
            tabHost.setOnTabChangedListener(new OnTabChangeListener(){
                 @Override
                 public void onTabChanged(String tabId) {
                     Log.i("TabId :", tabId);
                     if(tabId.equals("TAB1")){
                     Log.i("TAB1", "TAB1 Changed");
                     Intent intent1 = new Intent().setClass(getApplicationContext(), Tab3Activity.class);
                     sp1.setIndicator("TAB1").setContent(intent1);
                     tabHost.setCurrentTab(0);
                     }
                  }
            });

            Button addNewButton = (Button)findViewById(R.id.add_new_ticket_btn);
            addNewButton.setOnClickListener(new OnClickListener(){
                  @Override
                  public void onClick(View v) {
                     Intent in = new Intent().setClass(getApplicationContext(), AddNewTicketActivity.class);
                     sp1.setContent(in);
                     tabHost.setCurrentTab(0);
                     //startActivity(in);
                 }
            });               
      }
}
最佳回答

As I understand, when you click the button AddNewTicketActivity is shown in TAB1. Then you go to TAB2 and when you come back to TAB1, you want to see TAB1Actvity. In that case try this in onTabChanged method

          if (tabId.equals("TAB2")){
                    Intent intent1 = new Intent(this, Tab1Activity.class);
                    sp1.setIndicator("TAB1").setContent(intent1);
           }
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签