我有一个带有 2 个选项卡的 Tabview,在我的 TabActivity 中,有一个按钮。单击按钮时,我想将数据发送到当前选项卡并将数据显示到当前选项卡。当我烤这个数据时,数据是可用的,但是当我把这个数据设置为 textview 时,我的 textview 没有改变。如何从 tabhost 活动刷新我的标签内容?(对不起我的英语不好:P)这是我的代码:
public class MainActivity extends TabActivity {
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = getTabHost();
Bundle b = new Bundle();
b.putInt("category_id", 10);
Intent tab1Intent = new Intent(this, Tab1Activity.class).putExtras(b);
TabSpec tab1Spec = tabHost
.newTabSpec("Tab1")
.setIndicator("Tab1",
getResources().getDrawable(R.drawable.credit_tab_icon))
.setContent(tab1Intent);
tabHost.addTab(tab1Spec);
Intent tab2Intent = new Intent(this, Tab2Activity.class);
TabSpec tab2Spec = tabHost
.newTabSpec("Tab2")
.setIndicator("Tab2",
getResources().getDrawable(R.drawable.credit_tab_icon))
.setContent(tab2Intent);
tabHost.addTab(tab2Spec);
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 80;
}
tabHost.getTabWidget().setCurrentTab(0);
Button ok = (Button) findViewById(R.id.ok);
ok.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt("category_id",103);
LocalActivityManager manager = getLocalActivityManager();
String currentTag = tabHost.getCurrentTabTag();
Class<? extends Activity> currentClass = manager.getCurrentActivity().getClass();
manager.destroyActivity(currentTag, true);
manager.startActivity(currentTag, new Intent(MainActivity.this, currentClass).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtras(bundle));
}
});
}
@Override
public void onResume() {
super.onResume();
}
}
这是我的 Tab1Activity:
public class Tab1Activity extends Activity {
public static Tab1Activity s_childActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
}
public void onResume() {
super.onResume();
Bundle extras = this.getIntent().getExtras();
int get_category_id = extras.getInt("category_id");
Toast.makeText(this, "category_id = " + get_category_id,
Toast.LENGTH_SHORT).show();
TextView textView1 = (TextView)this.findViewById(R.id.textView1);
textView1.setText("Berubah"+get_category_id);//==> Textview not change with category_id
}
}