I am having trouble setting the content on a tab that I’ve inflated from an XML file.
I add the tab to my TabHost (‘tabs’) dynamically by doing the following:
TabSpec passSpec = tabs.newTabSpec("Pass Tab");
passSpec.setIndicator("Passengers", getResources().getDrawable(R.drawable.tab_message));
passSpec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
View layout = mInflater.inflate(R.layout.tab_content_passengers, null);
return(layout);
}
});
tabs.addTab(passSpec);
This works fine…what I’m having trouble with is changing the content on that tab later on. Is there any way to accomplish this without re-inflating all of the tabs with brand new layouts?
I am trying the following and nothing happens:
mInflater = LayoutInflater.from(this);
View layout = mInflater.inflate(R.layout.tab_content_passengers, null);
TextView t = (TextView) layout.findViewById(R.id.testText);
t.setText("Hello world??");
You can keep a reference to the
layoutvariable (maybe in a map or something) and then programmatically modify it later on like this:As long as you do it on the UI thread the changes should be reflected immediately.