Pregunta

i have implemented activity group in tab host.having 4 activity group.in every first activity of each activity group i have a back button.i am facing one problem.let's assume i am having 4activity group say A,B,C,D.now when application launch,on that time activity group A will be there,when i swith from A->B on than from B->C,now i am in activity group called C.now when i click back button of activity group of a C.on that time current tab of tab host should be prevous tab host from which i have navigated to C.is there any standard method to do that or we need to put as per our logic?

Thanks

¿Fue útil?

Solución

There is no standard way to do that, but then again, anything is possible with some logic! I had a similar problem in my earlier app. I solved it by maintaining a stack of last opened tabs, and then overriding the back button pressed to remove the tabs from the stack. Some sample code is given below.
Initialize the variables as follows

tabIdStack = new Stack<Integer>();
openedTab = 0;

and then override the onTabChanged()

@Override
    public void onTabChanged(String tabId) {
        if (!backButtonPressed) {
            if (tabIdStack != null) {
                if (tabIdStack.size() == noOfTabs)
                    tabIdStack.remove(0);
                tabIdStack.push(openedTab);
                openedTab = tabHost.getCurrentTab();
            }
        }
        backButtonPressed = false;

and then you should also override the onBackPressed()

@Override
    public void onBackPressed()
    {
        backButtonPressed = true;
        if (tabIdStack.size() == 0)
            this.finish();
        else {
            tabHost.setCurrentTab(tabIdStack.get(tabIdStack.size() - 1));
            tabIdStack.remove(tabIdStack.size() - 1);
        }       
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top