0

Tab含むカスタムレイアウトを持つがありますTextView。後で実際のタブの子からそのテキストを更新する必要があります。

これが私がそれを設定する方法ですTabActivity

    private void setupTab(final String tag) {

//Call createTabView() to give the tab a layout with some text
        View tabview = createTabView(mTabHost.getContext(), tag);

        Intent intent = new Intent().setClass(this, MyActivity.class);
        TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);

        mTabHost.addTab(setContent);
        mTabList.add(setContent);

    }


    private View createTabView(final Context context, final String text) {
            View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
            TextView tv = (TextView) view.findViewById(R.id.tabsText);
            tv.setText(text); //we set the text of the tab here.

            LinearLayout tvX = (LinearLayout) view.findViewById(R.id.tabsLayout);

            return view;
        }

設定方法は次のとおりです...子タブのアクティビティで、テキストを更新する必要があります...カスタムタブがない場合は、次のように機能すると思います...

((TabActivity)getParent()).getTabHost().setTag(((TabActivity)getParent()).getTabHost().getCurrentTab(), "new text");

しかし、カスタムタブが必要です:)

誰かアイデアや提案はありますか?ありがとう

4

1 に答える 1

0

わかりました!

TabActivity私はこの方法を持っています:

protected void updateText(int key, String text) {
    View view = mTabHost.getCurrentTabView();
    TextView tv = (TextView) view.findViewById(R.id.tabsText);
    tv.setText(text);       
}

そして、子タブでこれを呼び出します:

((MyTabActivity)getParent()).updateText(((TabActivity)getParent()).getTabHost().getCurrentTab(), "The new text");

そして今、あなたは知っています:)

于 2012-02-12T04:59:16.283 に答える