Reputation: 125
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. *(Thanks StinePike) Now I know I cannot get the instance of TabHost, but still, I can't call the methods defined in my own TabActivity. *
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(String startPage){
//...Add a new Tab
}
public void setTabTitle(String title){
//...Set new title
}
}
Upvotes: 1
Views: 2391
Reputation: 13254
TabActivity is deprecated (http://developer.android.com/reference/android/app/TabActivity.html). Please consider using something else:
Upvotes: 0
Reputation: 54682
from child call
RootActivity parentActivity;
parentActivity = (YourRootActivity) this.getParent();
parentActivity.setTitle(title);
In parent define setTitle(String s)
method
public void setTitle(String s){
// set title here
}
Upvotes: 3