5

我在从 XML 文件膨胀的选项卡上设置内容时遇到问题。

我通过执行以下操作将选项卡动态添加到我的 TabHost(“选项卡”):

        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);

这很好用......我遇到的问题是稍后更改该选项卡上的内容。有没有办法在不使用全新布局重新填充所有选项卡的情况下完成此操作?

我正在尝试以下操作,但没有任何反应:

    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??");
4

2 回答 2

4

您可以保留对layout变量的引用(可能在地图或其他东西中),然后稍后以编程方式对其进行修改,如下所示:

tabMap.get(tabId).findViewById(R.id.testText).setText("The text is changed now!");

只要您在 UI 线程上执行此操作,更改就会立即反映出来。

于 2011-06-22T20:48:22.910 回答
0

试着做

t.invalidate();

这应该迫使它重绘

于 2011-06-22T20:47:52.817 回答