سؤال

I have a Tab that has a custom layout which contains a TextView. I will need to later update that text from the actual tab child.

Here's how I set it up in the 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;
        }

So there is how I set it up... Now, in the child tab's activity I need it to update the text... I think the following would work if I didn't have custom tabs...

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

But I need custom tabs :)

Does anyone have any ideas or suggestions? Thanks

هل كانت مفيدة؟

المحلول

OK i got it figured out!

In the TabActivity I have this method:

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

And then in my child tab I call this:

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

And now you know :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top