问题描述
我有2个活动:A,B.第一个是TabActivity,第二个是Activity.在A内,我有一个可点击的按钮,可以用来调用其他活动.
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);
}
}
}
在B内部,每次单击A类中的按钮时,我都有一个线程从Internet获取数据:
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();
}
数据可以正确返回,并且我可以管理它,但是我的Tabhost消失了.我该怎么解决?
Data returns correctly and I can manage it, but my tabhost disappear. How I can solve?
推荐答案
自动更改标签页的android方法是:
The android way to automatically change tab is:
tabHost.setCurrentTab(tab);
不使用:
startActivity(intent);
要在所有Activity上使用它,最好的方法是将TabHost设置为公共和静态.
To use it on all your Activity the best way is to set your TabHost public and static.
这篇关于创建意图onClick按钮的TabActivity,但活动接收器的tabhost消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!