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 layout
variable (maybe in a map or something) and then programmatically modify it later on like this:
tabMap.get(tabId).findViewById(R.id.testText).setText("The text is changed now!");
As long as you do it on the UI thread the changes should be reflected immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With