TabActivity创造一个意图的onClick按钮,但活动reciver的tabhost消失 [英] TabActivity that create an intent onClick button but the tabhost of activity reciver disappear
问题描述
我有2个活动:A,B。首先是TabActivity,第二一个活动。
里面我有一个可点击按钮,使一个意图调用其他活动。
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,我有一个线程从互联网上每一个类别中的按钮被点击时得到的数据:
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);
要使用它在所有的活动最好的办法是设置TabHost公共和静态的。
To use it on all your Activity the best way is to set your TabHost public and static.
这篇关于TabActivity创造一个意图的onClick按钮,但活动reciver的tabhost消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!