0

I have 2 activity: A, B. The first is an TabActivity and the second an Activity. Inside A i have a clickable button that make an intent to call the other activity.

public class A extends TabActivity implements OnClickListener {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tabHost = getTabHost();
        tabHost.addTab(tabHost.newTabSpec("a").setContent(R.id.a).setIndicator("a"));

        b = new Intent(this,B.class);
    tabHost.addTab(tabHost.newTabSpec("b").setContent(b)
            .setIndicator(this.getString(R.string.b)));

        btn.setOnClickListener(this);
    }


    public void onClick(View arg0) {
        if (arg0 == btn) {
        startActivity(b);
        }
    }
}

Inside B, i have a thread that gets data from internet every time that the button in A class is clicked:

public class B extends Activity {
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.search_result);

       searchHandler = new Handler() {
           @Override
           public void handleMessage(Message msg) {
               draw(msg.obj.toString());
           }
    }

    Intent intent = getIntent();
    if(..)
        sendHttpRequest();
}

Data returns correctly and I can manage it, but my tabhost disappear. How I can solve?

Cœur
  • 37,241
  • 25
  • 195
  • 267
jedi
  • 839
  • 12
  • 33

2 Answers2

1

The android way to automatically change tab is:

tabHost.setCurrentTab(tab);

and not using:

startActivity(intent);

To use it on all your Activity the best way is to set your TabHost public and static.

jedi
  • 839
  • 12
  • 33
0

whenever you click a button you call an activity which is not child activity of tab activity. so tabhost is disapear. call activity b in tab activity just like this

 tabHost.addTab(tabHost.newTabSpec("Tab")
                    .setIndicator("Tab")
                    .setContent(new Intent(this, b.class)
                   ));
Zaz Gmy
  • 4,236
  • 3
  • 19
  • 30
  • correct, but how can i have the behavior that i would like to have? – jedi May 03 '12 at 22:32
  • use tabchangedListener and on tabChanged method call you method.every time you change tab this method is called – Zaz Gmy May 04 '12 at 04:09
  • 1
    I continue to don't understand how i can implement the workflow that i would. Only to be sure that you misunderstand me. I need to draw an activity associated to a tab B, but not clicking on the switch of tabs. Clicking on it, i only need to display what i have generated with a click on a button viewed on of the activity (A), but i would that the switch of tabs continue to be present. If you think that your reply is still correct i would like more explanation. – jedi May 04 '12 at 14:06