开发者

Interchange data between TabActivity and its sub-Activities. Possible?

I have a list of locations saved in the TabActivity. The TabActivity has 2 sub-activities: a map and a list. So i want to get the location-list to the sub-activities to show them there. I know that i can commit some data with the intent, but i always want to commit the data to the current showing sub-activity if the list changes. Is there a possiblity 开发者_如何学JAVAto do this?

For further details, please ask me.

Thanks a lot, joe


Yes it is possible, You can have access to the sub activities of TabActivity. You can get the current active Activity like this way:

say you have a Button(typically other than TabIndicators) somewhere in TabActivity which call doSomeAction() in its onClick() to refresh or change your Sub-Activity contents. You will do it this way:

//this method is in TabActivity
public void doSomeAction(View button)
{
    Activity currentAct = this.getLocalActivityManager().getCurrentActivity();
    int index = getTabHost().getCurrentTab();
    if(index == 0)
    {
        MyListAct listAct = (MyListAct)currentAct; //MyListAct or any other Sub Activity
        listAct.refreshList(); // refreshList() may be a method to refresh Activity    
    }
    //else you can check for the other Activity
}


I would suggest to create a static global data container and commit your changes into that object (you could clear and setup it with the aid of the main activity life cycle). But make sure you don't leak any heavy resources, especially a context reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜