Tuesday, April 16, 2013

[android help] How to call a function in TabActivity from a child activity?


I want to update the title of the tab according to the content of my child activity.


However, when I call:



TabActivity parent = (TabActivity) getParent();
TabHost parentHost = (TabHost) parent.getTabHost().findViewById(android.R.id.tabhost);


in the child, the program crashes.


Anyone can help me discover the problem and solve it?


My TabActivity setup:



public class Tab extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tab);

final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

View newTab = (View) LayoutInflater.from(this).inflate(R.layout.tabmini, null);
TextView text0 = (TextView) newTab.findViewById(R.id.tab_label);
text0.setText("new tab");

tabHost.setup(this.getLocalActivityManager());
tabHost.setCurrentTab(1);

tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(newTab).setContent(new Intent(this, BrowserActivity.class)));

}

public void addTab(TabHost tabHost, String startPage){
//...Add a new Tab
}

}


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...